[Haskell-cafe] Re: [Haskell] Top Level <-
ahey at iee.org
Wed Aug 27 09:15:14 EDT 2008
Judah Jacobson wrote:
> I've been wondering: is there any benefit to having top-level ACIO'd
> <- instead of just using runOnce (or perhaps "oneshot") as the
> primitive for everything? For example:
> oneshot uniqueRef :: IO (MVar Integer)
> uniqueRef =< newMVar 0
I've been wondering about something like this too (in some way just have
a oneShot or runOnce and the *only* thing in ACIO as a magic primitive).
runOnce :: IO a -> ACIO (IO a)
It would certainly simplify the ACIO monad :-), but I'm not sure it's
really as flexible. Provided newMVar can be ACIO then this can be
implemented directly (doesn't need to be a primitive). But we can't
go the other way round (use runOnce to create genuine top level MVars
or channels say).
Does that matter? Probably not for monadic IO code. It's not a huge
inconvenience to write..
thing <- getThing
foo thing -- thing is at top level
But for top level non monadic code/expressions/data structures I can
see a certain convenience in having thing as top level identifier
if possible, which it often won't be anyway I guess for other
reasons (like it's creation and initialisation requires real IO).
So I don't have any particularly strong opinion either way. In
practice if thing (or getThing) is to be exported then it
would probably be prudent to assume creation and initialisation
might require real IO at some point in the future even if they
don't right now, so you'd export getThing (= return thing) anyway,
rather then have an exported thing dissappear from the API at some
More information about the Haskell-Cafe