unsafePerformIO and IORefs

Nicolas Oury Nicolas.Oury@ens-lyon.fr
Mon, 18 Nov 2002 19:34:13 +0100


I want to write something like

type State a = IORef a

newState :: a -> State a
newState v = unsafePerformIO (newIORef  v)


But I don't want the compileer to inline this nor to inline any 
application of this.

{#NOINLINE newState#}

But how can I stop this function to be inlined when applied for example :
....
let x = newState 0 in
{... code where x is used twice ...}

How to be sure that x isn't inlined and that all occurences of x are 
pointing to the same memory place ?

Best regards,
Nicolas Oury