Hash in Haskell

Sergio Sebastián Giro sergio@fceia.unr.edu.ar
Mon, 16 Jun 2003 23:07:32 -0300 (ART)


On Mon, 16 Jun 2003 gilesb@cpsc.ucalgary.ca wrote:
Thanks anyway, but I want to maintain a set of elements of some (fixed)
unknown type. In a hash table, I can see in O(1) aprox. if the element
belongs  or not to set.

> Typically, such functions are often used to implement mappings from
> something (such as a String) to something else.
>
> 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án 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
>
> --
> 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
>
>