On 12 Oct 2004, at 18:59, Marcin 'Qrczak' Kowalczyk wrote:
Jules Bean <[EMAIL PROTECTED]> writes:
I think what people are trying to suggest is an 'initialization phase' in the IO monad, which takes place "before" the pure functions are defined.
If it was done before, what could you use to specify initial value of such a variable? Only literals? Constructors? Named constants? Results of arithmetic operations? Results of arbitrary functions?
Yes, that's what I was trying to get at. But you said it much better...
The well-definedness of a global IORef relies on the fact that creation of an IORef doesn't have visible side effects, so it doesn't matter when it happens, as long as it happens once between the variable is used. An arbitrary IO computation doesn't have this property.
Indeed.
There are other hacks you can think of, though, if IORefs are your only goal. For example, something like
getIORef :: Int -> a -> IORef a
or
getIORef :: String -> a -> IORef a
(importantly, it's IORef, not IO IORef.) But this isn't great for programmer convenience, since there's nothing to help him discipline the use of particular variables.
All we really need is a 'unique value monad' to give us unique values to be keys for IORefs (or whatever else), and allow this monad to be accessible at the top level. Conceptually this monad is commutative, so ordering of the actions doesn't matter.
Jules
_______________________________________________ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
