[Haskell-cafe] FiniteMap-like module for unordered keys?
Remi Turk
rturk at science.uva.nl
Wed Nov 10 17:26:32 EST 2004
Ugh, replying to myself...
Obviously, the following contains a few mistakes...:
On Wed, Nov 10, 2004 at 11:34:32AM +0100, R. Turk wrote:
> {-# OPTIONS -fglasgow-exts #-}
> {- I want a Hashable instance for String ;) -}
> import Data.FiniteMap
> import Data.HashTable (hashInt, hashString)
> import Data.Int (Int32)
>
> class Hashable a where hash :: a -> Hash
> instance Hashable Int where hash = hashInt
> instance Hashable String where hash = hashString
>
> type Hash = Int32
> newtype HashTable a b = HT (FiniteMap Hash [b])
newtype HashTable a b = HT (FiniteMap Hash [(a,b)])
>
> emptyHT :: HashTable a b
> emptyHT = HT emptyFM
>
> addToHT :: (Hashable a) => HashTable a b -> a -> b -> HashTable a b
> addToHT (HT m) k v
> = HT $ addToFM_C (flip (++)) m (hash k) [v]
addToHT (HT m) k v
= HT $ addToFM_C (flip (++)) m (hash k) [(k,v)]
--
Nobody can be exactly like me. Even I have trouble doing it.
More information about the Haskell-Cafe
mailing list