On glasgow-haskell-users, Simon Peyton-Jones <[EMAIL PROTECTED]> answered my question arising from a different thread: > > | This is something that I have long been wondering about > | (perhaps it is just because of my ignorance): > | Wouldn't stable pointers be a cheaper and more appropriate means > | to get Ord for MVars, STRefs, and IORefs? > > Could be -- but do we really want to clog up the stable-pointer table > with an entry for every MVar, whether or not anyone is interested in > ordering? To this I replied after some motivation: I would already be happy if IORefs, STRefs and MVars came with a variant in Ord (consider this as a concrete proposal for the standard library) --- even if some implementations choose to implement that via the Integer trick: hopefully the best implementations would provide something faster ;-) This was not explicit enough --- Simon replied correctly: > Are you saying that adding an Integer > to each graph node slows things down unacceptably? If we add a unique > Id to every IORef, that will slow down every IORef in a similar way. > I'm still having trouble getting clear why it's a good thing to > tie together these unique stamps with IORefs. > Now, adding the unique ID is slower than having integer indices instead of IORefs as access information; with the integers as array indices, however, I do memory management myself. I really want neither of the two. My thought was that using stable pointers instead of unstable pointers for IORefs should provide a cheap Ord (plain low-level pointer comparison) without memory or access time penalties. But perhaps I do not know enough about stable pointers... If this is too expensive to do for all IORefs, then I am happy with an additional type IOORefs that provides the same interface as IORefs (put that in a class!), plus Ord. And this Ord would be eefficiently implemented via stable pointers in the best implementations, and less efficiently via unique tags in the other implementations ;-) Then I would use IOORefs only where necessary. What kinds of costs are incurred by the stable pointer table? And if Ord sounds too Unsafe in this context, then I would be happy with any Mappable class that suffices as precondition for efficient FiniteMap-like data types. (Internally equivalent to Ord, but not visible to the end user.) Wolfram