{- Finite maps.
   Uses lists for simplicity and to make the semantics clear.
   A real implementation should use balanced trees or hash tables.
-}

module Map (Map,
	    mempty,
	    mget,
	    mset)
where

import List
import Maybe

data Map a b = Map [(a,b)] 
 deriving (Show,Eq)

mempty :: Map a b 
mempty = Map []

{- In case of duplicates, returns most recently added entry. -}
mget:: (Eq a) => Map a b -> a -> b
mget (Map l) k = fromJust (lookup k l)

{- May hide existing entries. -}
mset :: Map a b -> (a,b) -> Map a b
mset (Map l) (k,d) = Map ((k,d):l)

