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

Keean Schupke k.schupke at imperial.ac.uk
Fri Nov 12 10:20:40 EST 2004


Adrian Hey wrote:

>The latter is probably true, in a strict technical sense. But I can't
>see a way to live without them and keep modularity. In any case,
>I don't think there's any reason to force programmers "wear the hair
>shirt" in this respect (other than dogma and superstitious fear about
>the evils of "global variables" :-)
>  
>
I agree about not wearing a hair-shirt, but how do you propose to solve
the multiple import problem: B imports A, C imports A, D imports B & C.
Now the top level inits (a <- computation) in A, do they happen once, 
defining
the same init A.a, do they happen twice, perhaps initialising B.A.a and 
C.A.a,
do they happen twice, meaning that 'a' may have different values depending
on whether it is accessed from B or C? for example:

module A where
    a <- newChan 0

module B where
    import A
    b <- do {writeChan A.a 7;return ()}

module C
    import A
    c <- do {writeChan A.a 6;return ()}

module D
    import A
    import B

    d <- readChan A.a

does this mean the same as:

module D'
    import B
    import A

    d <- readChan A.a


Should values really depend on the order of includes? Even if you limit 
things to just
newChan in top level '<-' you still don't know if A.a in B the same A.a 
in C. Perhaps it
is enough to say  A.a only exists once no matter how many times it is 
directly or
indirectly imported?

    Keean.




More information about the Haskell-Cafe mailing list