In article <[EMAIL PROTECTED]>,
 John Meacham <[EMAIL PROTECTED]> wrote:

> I am a fan of allowing top level declarations of the form:
> 
> foo <- newIORef "foo"
> 
> which would behave as an initializer, with the semantics being that it
> be evaluated at most once before foos first use. (so it could be
> implemented via unsafePerformIO or as an init section run before main).
> 
> The 
> {-# NOINLINE foo #-}
> foo = unsafePeformIO $ newIORef "foo"
> 
> idiom is so common and useful, it should have some compiler support. It
> is 'clean' too, since all we are doing is extending the "world" with new
> state, but in a much cleaner/safer way then writing to a file or environment
> variable or other methods of storing state in the world.

Clean it is not:

foo :: a
foo <- newIORef undefined

writeChar :: Int -> IO ()
writeChar x = writeIORef foo x

readString :: IO String
readString = readIORef foo

cast :: Char -> IO String
cast c = (writeChar c) >> readString

-- 
Ashley Yakeley, Seattle WA

_______________________________________________
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to