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

Adrian Hey ahey at iee.org
Fri Nov 12 09:53:33 EST 2004


On Thursday 11 Nov 2004 12:27 pm, Ben Rudiak-Gould wrote:
> On the other hand, these are perfectly safe:
>
>     once' :: IO a -> IO (IO a)
>     oncePerString :: String -> IO a -> IO a
>     oncePerType   :: Typeable a => IO a -> IO a
>
> once' seems virtually useless unless you have top-level <-, but the
> other two don't need it. I'm not sure which would be preferable. I lean
> toward oncePerString as more flexible and predictable, though it
> requires a certain discipline on the part of its users.

Having taken a bit of time to look at this, I have to say that IMO
saying they are "perfectly safe" is over stating things a bit :-)

The only one that is perfectly safe is the first, but as you say,
is useless (at least for the purposes under discussion) without
the top-level <- extension. AFAICS the other two are unsound hacks.

So it seems to me that either the top-level <- extension (in one form
or another) really is necessary, or that top level TWI's are unnecessary.

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" :-)

Regards
--
Adrian Hey
 


More information about the Haskell-Cafe mailing list