Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test IORef identity?

Tags:

haskell

In Haskell, is there a way to test whether two IORefs are identical? I'm looking for something like this:

IORef a -> IORef a -> IO Bool

This would be useful if you want to visualize a graph made of IORefs, for example. I don't think it would break referential transparency, because IORefs have a meaningful identity (and the result could be in IO, anyway). And I assume it wouldn't be hard to implement this efficiently, as a pointer comparison.

Is this available somewhere? Or if not, why not?

(Edit: I just found System.Mem.StableName from a different SO question, which looks helpful.)

like image 630
dpercy Avatar asked Dec 18 '22 13:12

dpercy


1 Answers

Don't overthink it. You have instance Eq (IORef a), so you can just use ==, and the result isn't even in IO.

like image 66
Joseph Sible-Reinstate Monica Avatar answered Jan 01 '23 23:01

Joseph Sible-Reinstate Monica