[Yhc] coreFunc has extra argument
shackell at cs.york.ac.uk
Tue Mar 4 11:01:18 EST 2008
Tom Hawkins wrote:
> Thanks Tom and Jeremy, this helps a lot. Actually, Tom I see you
> spelled this out for me a couple weeks ago in an earlier post. Sorry,
> I'm a bit slow.
Not at all, it's actually quite complex. It took me a couple of attempts
to get the IO type right. It has many funny features, and the reasons
that some of them are there is quite subtle :)
> So am I correct in saying that World is never reference in the
> program, it's only used to emulate imperative actions?
The value of World comes up in only two places that I know of. The first
is in the startup code. When the interpreter starts it calls the
YHC._Driver._driver function, passing it a value of type World and the
'main' function to evaluate.
_driver :: World -> IO () -> a
In fact _driver doesn't even use the World value it is passed, its
existence in that function is entirely historical and it could be
removed if anyone could be bothered :)
The second, and more useful, example is unsafePerformIO. Defined in
unsafePerformIO :: IO a -> a
unsafePerformIO (IO f) = case f World of
_E x -> x
This takes an IO action, unpacks it, applies World to it (which the IO
action will never look at) and then gets the result.
So World is created, and passed as an argument, but (as far as I know)
it is never cased on. It's also only ever used inside the IO monad.
Hope that helps :)
More information about the Yhc