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.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to