Hashcode for reference

Mathieu Giorgino mathieu.giorgino at irit.fr
Wed Sep 29 07:20:52 EDT 2010


Le mercredi 29 septembre 2010 18:00:20, Simon Marlow a écrit :
> 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

Great, I will dig into this direction.

Thanks a lot,

Mathieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20100929/753b6768/attachment.html


More information about the Glasgow-haskell-users mailing list