
would it be possible to provide an Ord instance for (IORef a)? For things like loop detection, one may need to make many IORef comparasions and being able to use an efficient set would be a really big win. Since IORefs are created in the IO monad, the actual order can be arbitrary without breaking referential transparency (as long as it doesn't change over the lifetime of the IORef.) John -- John Meacham - ⑆repetae.net⑆john⑈

G'day all.
Quoting John Meacham
would it be possible to provide an Ord instance for (IORef a)?
It would, although then someone else would just want a hashable instance. Sounds to me like it might be worth coming up with a general IORef (and STRef) wrapper. Until then, this is what I use. Cheers, Andrew Bromage

John Meacham wrote:
would it be possible to provide an Ord instance for (IORef a)? For things like loop detection, one may need to make many IORef comparasions and being able to use an efficient set would be a really big win.
Since IORefs are created in the IO monad, the actual order can be arbitrary without breaking referential transparency (as long as it doesn't change over the lifetime of the IORef.) John
Someone posted an 'inside out' solution to this a while ago, but I'm having trouble finding it in the mail archives. It was along these lines: type CollectionOfIoRef = Int newtype IoRef a = IoRef (IORef (a, Array CollectionOfIoRef Bool)) You use this wrapper, IoRef, instead of IORef. To insert a reference into a collection, you add the *collection* to the IoRef's hidden set. Regards, Tom
participants (3)
-
ajb@spamcop.net
-
John Meacham
-
Tom Pledger