[Haskell] Re: Global Variables and IO initializers

Jules Bean jules at jellybean.co.uk
Sat Nov 6 08:20:21 EST 2004


On 6 Nov 2004, at 13:07, Keean Schupke wrote:

> Just been reading arround. According to ghc docs, the noinline
> pragma is in the Haskell98 report. On that basis what is wrong
> with using the following to initialise these top-level constants?
>
>    {-# NOINLINE newref #-}
>    newref :: IORef Int
>    newref = unsafePerformIO $ newIORef 0
>

What's wrong is that it isn't haskell. (NOINLINE may be in the haskell 
report, but unsafePerformIO isn't.. and without unsafe operations, 
NOINLINE is of course quite safe)

> myRef1 = unsafePerformIO $ newIORef 0
> myRef2 = unsafePerformIO $ newIORef 0

In a referentially transparent language, these two values myRef1 and 
myRef2 *must* be the same. That's the whole thrust of referential 
transparency.

But it is certainly not what the user intends....

Jules



More information about the Haskell mailing list