[Haskell] Re: Global Variables and IO initializers

Jon Fairbairn Jon.Fairbairn at cl.cam.ac.uk
Thu Nov 4 11:59:29 EST 2004


On 2004-11-04 at 16:16+0100 Koen Claessen wrote:
> Benjamin Franksen wrote:
> 
>  | 1) I strongly disagree with ideas to execute IO actions
>  | implicitly in whatever defined or undefined sequence
>  | before or during main for whatever reasons.
> 
> I agree with the objections you make. Having full IO actions
> as initialization actions might be a bit too much.

I agree with that too. Let me propose what I think may be a
simpler (though at present the dough is barely risen, let
alone baked) alternative: external "constant" modules.

First, I'd like to point out that having initialisation data
that changes between runs of a programme is already
possible: a programme could do IO to its own loadmodule. I
mention this not as a serious suggestion, but to forestall
objections about changing the content of a "constant"
module.

The idea is simply that we should provide a mechanism of
saying to a compiler "this file (of data) is a module that
exports only the variable v". Given the way IO and
filesystems stand at the moment, this probably means that
we'd have to restrict v to be a String (or [Word8]?), but
the correct solution to that would be typed IO, and it's too
early to talk about that.

So we tell the compilation system that file
/somewhere/contains-v contains the value of the variable
v::String, and that it lives in the imaginary module
Home.Of.V, and when the resulting programme is loaded, so is
the content of /somewhere/contains-v, and v is bound to it.
OS permitting the loading of the file should only be
virtual.  Now IO to /somewhere/contains-v should have no
effect on the value of v, but next time the programme starts
it can use the new value.


  Jón

-- 
Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk




More information about the Haskell mailing list