question about RealWorld and realWorld#
Bernard James POPE
bjpop@cs.mu.OZ.AU
Wed, 31 Jul 2002 17:31:48 +1000 (EST)
Hi all,
Am I right in saying that the type constructor
RealWorld is special to the compiler in that it is not defined in
any Haskell code but wired in?
ie this is its only definition in ghc (ghc/compiler/prelude/TysPrim.lhs):
realWorldTyCon
= mkLiftedPrimTyCon realWorldTyConName liftedTypeKind 0 [] PrimPtrRep
realWorldTy = mkTyConTy realWorldTyCon
It seems to be visible throughout the compiler but I can't find anywhere
that explicitly exports it. I think the comment in TysPrim.lhs probably
answers my question, but I'm not 100% sure.
Am I also correct is saying that the identifier realWorld# is similar in
that it isn't defined in any Haskell code, but is primitive to the compiler?
I would have expected to find something like:
realWorld# :: State# s
realWorld# = undefined
My instinctive feeling is that GHC treats State# objects specially, so that
they only live at compile time but are not present at runtime. This is mentioned
in the "Lazy functional state threads" paper:
"By the time the program reaches the code generator, the role of the state
values is over, and the code generator arranges to generate no code at all
to move around values of type State#" (page 13 in my version of the paper).
The reason I ask is that things have changed somewhat since that paper was written
and I wanted to be absolutely sure about the details in the current compiler.
I must admit that I always found runST a little weird in that is somehow
manages to conjure up an initial state for me. I now see how it does it.
Cheers,
Bernie.