Hashcode for reference

Simon Marlow marlowsd at gmail.com
Wed Sep 29 12:00:20 EDT 2010


On 29/09/10 04:54, Mathieu Giorgino wrote:
> Hi all,
>
> I'm wondering if there is a way to get an hashcode from references
> (IORef or STRef)? I have looked in the library and a little in the
> sources of GHC but haven't found anything allowing to do this.
>
> I'm generating Haskell code from the Isabelle/HOL proof assistant, which
> generate "generic" code for other langages too which all have this
> notion, and I would so need an equivalent in Haskell.
>
> Have you any hint on how to achieve this, or even if it is possible?

IORefs themselves have no persistent properties that could be used to 
make a hash value, so you would have to implement this yourself on top 
of IORef, perhaps using Data.Unique for example.  Something like this:

  data IdIORef a = IdIORef Unique !(IORef a)

  newIdIORef :: a -> IO (IdIORef a)
  newIdIORef a = do
    u <- getUnique
    r <- newIORef a
    return (IdIORef u r)

Cheers,
	Simon


More information about the Glasgow-haskell-users mailing list