2 Uses lists for simplicity and to make the semantics clear.
3 A real implementation should use balanced trees or hash tables.
18 data Env a b = Env [(a,b)]
24 {- In case of duplicates, returns most recently added entry. -}
25 elookup :: (Eq a) => Env a b -> a -> Maybe b
26 elookup (Env l) k = lookup k l
28 {- May hide existing entries. -}
29 eextend :: Env a b -> (a,b) -> Env a b
30 eextend (Env l) (k,d) = Env ((k,d):l)
32 edomain :: (Eq a) => Env a b -> [a]
33 edomain (Env l) = nub (map fst l)
35 {- In case of duplicates, first entry hides others. -}
36 efromlist :: [(a,b)] -> Env a b
39 eremove :: (Eq a) => Env a b -> a -> Env a b
40 eremove (Env l) k = Env (filter ((/= k).fst) l)
42 efilter :: Env a b -> (a -> Bool) -> Env a b
43 efilter (Env l) p = Env (filter (p.fst) l)