How can I hash a string in haskell to get a more-or-less unique hash value. For example:
hash:: String -> Integer
>hash "foo"
1234123412
>hash "bar"
5938454
Or something along those lines? I’m not familiar with hashing in haskell so any help would be appreciated! Thanks.
You can use the hashable package from Hackage. It provides hash functions for a number of standard types, including strings:
If you want to implement your own, hash functions are usually easy to express as a fold. For example, here’s a variant of the DJB2 hash:
Note that these hash functions are meant to be simple and fast. If you’re looking for more complex hash functions, you can find a selection in the cryptohash package.