[Haskell-cafe] One-shot? (was: Global variables and stuff)

Keean Schupke k.schupke at imperial.ac.uk
Sat Nov 13 04:15:48 EST 2004


>I'm not sure I understand what problem you think there is. Are the inits
>you're talking about module inits? If so, I don't think there's a problem,
>for several reasons.
>
>The idea under discussion is that a top level (x <- newThing) should
>be lazy, (no action at all occurs until value of x is demanded). IOW,
>it's exactly the same as the current unsafePerformIO hack, but not unsafe
>because the compiler knows the semantics. So there is no implied "module 
>initialisation"
>
Okay - I can see that with lazy semantics this might not be a problem... 
What happens with
the second problem: That where module B uses A internally and C uses A 
internally, then
I write a new module that tries to use B & C together... This 
potentially breaks B & C. I think
you need the extra restriction that the top level '<-' bindings must not 
be exported. So where
does that leave us.

Top level inits are safe (I think) iff:
    - They are lazy (the definition only happens when required)
    - They contain only a subset of IO actions - namely those concerned
          with name creation within Haskell that don't actually do any IO.
    - They are not exportable from the module that contains them.

I think that covers it... have I forgotten anything?

    Keean.



More information about the Haskell-Cafe mailing list