[Haskell-cafe] Ord (IORef a)?

Simon Marlow simonmar at microsoft.com
Wed Jun 23 05:48:34 EDT 2004

On 23 June 2004 03:53, John Meacham wrote:

> Yeah, i forgot about the GC moving things around. actually, if the GC
> could be coaxed to move things around, but never change the relative
> order of IORefs (like a compacting collector), then the address could
> still be used for Ord and Eq.

This is a rather restrictive global invariant, I don't think it's

> how is Eq implemented such that the GC doesn't move one side after you
> read the address of the other?

The sameMutVar# primitive is atomic with respect to the GC.

It ought to be possible to implement Ord on IORef using StablePtr, but
for some reason StablePtr isn't an instance of Ord.


More information about the Haskell-Cafe mailing list