[prev in list] [next in list] [prev in thread] [next in thread]
List: haskell-cafe
Subject: Re: [Haskell-cafe] FiniteMap-like module for unordered keys?
From: Remi Turk <rturk () science ! uva ! nl>
Date: 2004-11-10 22:26:32
Message-ID: 20041110222632.GA764 () localhost ! lan
[Download RAW message or body]
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.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic