Hash in Haskell

gilesb@cpsc.ucalgary.ca gilesb@cpsc.ucalgary.ca
Mon, 16 Jun 2003 12:07:57 -0600 (MDT)


Typically, such functions are often used to implement mappings from
something (such as a String) to something else.=20

If that is what you want take a  look at the type FiniteMap under the
Data area of GHC and HUGS. It implements all the needed functionality
without having to worry about creating a Hash for the keys.

If you want if for some other reason, you would typically need to define
a class such as:

Class Hash where
   hash::a->Int

and then implement it on your desired types. Strings are ususally
somewhat easy to create a unique has value, other types will, naturally,
depend on what is in them.



On 16 Jun, Sergio Sebasti=E1n Giro wrote:
> Hi, I need some function in Haskell to hash any value from any type to
> Int. I guess that such a function needs to be a primitive, but I don't
> found it in Hugs. Do you know how I can implement it or found it?
> Thanks
> Sergio
> _______________________________________________
> Haskell mailing list
> Haskell@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell

--=20
Brett G. Giles
Grad Student, University of Calgary
Formal Methods, Category Theory, Semantics of Programming
http://www.cpsc.ucalgary.ca/~gilesb     mailto:gilesb@cpsc.ucalgary.ca