Hacker News new | ask | show | jobs
by Peaker 4772 days ago
The RealWorld hack in GHC is not "passing the world state". It's just a hack/implementation detail to get evaluation order correctly. The RealWorld -> (RealWorld, x) view of IO is not a valid one.
1 comments

Quite correct. As I'm aware, when you call "main" in Haskell, you're actually building up a really gigantic curried function of type `IO x` (where x is your return type), and then the runtime system runs everything in the curried function all at once. The `RealWorld` symbol is more-or-less an existential type: we can't do anything with it, but it exists to make the type system acknowledge the monadic nature of IO so that we can use monadic combinators to order our curried I/O actions in preparation for their eventual run on real hardware.