[Haskell-cafe] global variables

Adrian Hey ahey at iee.org
Wed May 23 02:39:58 EDT 2007

Isaac Dupree wrote:

> var :: IORef Int
> var = {-# EVALUATE_THIS_TEXT_ONLY_ONCE #-} (unsafePerformIO (newIORef 3))

I think I still prefer..

var :: IORef Int
var <- newIORef 3

or, more likely..

var :: IORef Int
var <- ACIO.newIORef 3

The <- syntax should make the intended semantics clear and unambiguous,
so it becomes the problem of individual implementors (not standards
writers) to make sure that whatever optimisations or transformations
that may be appropriate for their implementation preserve those
semantics. (IOW there's no need to worry about what a pragma really
means in operational terms, AFAICS).

The ACIO monad also restricts what programmers may use on the rhs of
the <-.

But if you want a good name for the pragma how about this..

> var :: IORef Int
> var = {-# <- #-} (unsafePerformIO (newIORef 3))


Adrian Hey

More information about the Haskell-prime mailing list