[Haskell-cafe] Where is Data.Atom ?

Chris Kuklewicz haskell at list.mightyreason.com
Sun Jul 2 18:42:59 EDT 2006


Brian Hulley wrote:
> 
> The comparison would then be:
> 
>      compare (Atom l) (Atom r) = unsafePerformIO $ do
>            li <- readIORef l
>            ri <- readIORef r
>            return (compare li ri)
> 
> which is safe as long as creation of atoms is not allowed inside 
> unsafePerformIO (it would be nice if there was a way to tell the 
> typechecker that a specific action is not allowed in unsafe IO)
> 

That is highly unsafe with respect to multiple threads of evaluation.  You could 
be changing the li and ri value in between reading them.  Locking will be 
needed, assuming there is any sane way to manage locks inside unsafePerformIO.



More information about the Haskell-Cafe mailing list