[project @ 1999-01-15 10:49:05 by sof]
[ghc-hetmet.git] / ghc / tests / deSugar / should_compile / ds025.hs
1 -- !!! ds025 -- overloaded assoc -- AbsBinds
2
3 module Util where
4
5 ehead xs loc | null xs = error ("4"++loc)
6              | True = head xs
7
8 assoc key lst loc
9    = if (null res) then error ("1"++loc++"2"++(show key))
10                    else (ehead res "3")
11      where res = [ val | (key',val) <- lst, key==key']
12
13 assocMaybe :: (Eq a) => a -> [(a,b)] -> Maybe b
14 assocMaybe key lst
15  = if (null res) then Nothing else (Just (head res))
16    where res =  [ val | (key',val) <- lst, key==key']