
2 Jul
2006
2 Jul
'06
6:42 p.m.
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.