You can also look at Japan, where railroad isn't even the main moneymaker for the companies that operate them (pretty sure some even run at a loss). Instead, it's the hubs that those railroads create (ie all the real state connected to the stations which is owned by the railroad companies and can be rented out to businesses).
In essence, railroads shouldn't be built because they're profitable. They should be built because they're a basic necessity for unifying a country/region. The profit comes from the increased mobility and the new hubs and opportunity that mobility can create. But most politicians are too short-sighted for this.