[Haskell] (no subject)

Wolfgang Thaller wolfgang.thaller at gmx.net
Wed Oct 13 11:16:42 EDT 2004


> b) Some predetermined order, with semantics like mdo:

Hmm, I just realized that this also means we can execute moduke 
intialisation code that returns no result using:
_ <- do ...

I like that, I desperately need that for my Objective-C binding...
So the extension with the specified order actually allows one to do more 
things than the unsafePerformIO hack. I wouldn't care about specifying the 
order otherwise. If the default order is wrong, people can still use 
unsafeInterleaveIO.

> GHC already has an initialisation procedure for each module in the
> program which could be adapted to run the initialisation-time IO
> actions, with a little effort.

Hmm, doesn't the initialisation procedure run before the Stg machine is 
properly set up? I guess all the GHC init code could do is to register IO 
actions to be executed later (but before main is run). We probably want 
all the GHC module init procedures to be run before we execute any IO 
actions.

> I'm more worried about what other changes we have to make to the
> compiler: if we can avoid having to flag top-level bindings as
> monadic/non-monadic all the way through the compiler, then we could
> avoid a pervasive change to the compiler.  At the moment I can't see an 
> obvious way to do that.

We could get away with "desugaring" them to some very "unsafe" non-IO-
bindings and having the "module init action" do something evil to make the 
IO happen in the right order... should be possible to make that look 
exactly like mdo from the outside.
We'll end up using the unsafePerformIO hack inside the implementation 
again, so that people end up with two IORefs instead of one, but that 
should be cheap enough:

foo <- someAction

... could be transformed into ...

foo_var = unsafePerformIO $ newIORef (throw NonTermination)
foo_action = someAction >>= writeIORef foo_var
foo = unsafePerformIO $ readIORef foo

... with the appropriate NOINLINEs.
The module init action would then make sure that foo_action gets invoked.

So we'd only need to annotate modules with a list of init actions and 
extend the RTS appropriately for that...


Cheers,

Wolfgang

-- 
GMX ProMail mit bestem Virenschutz http://www.gmx.net/de/go/mail
+++ Empfehlung der Redaktion +++ Internet Professionell 10/04 +++



More information about the Haskell mailing list