[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / compiler / tests / deSugar / 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']
17
18 data Maybe a = Just a | Nothing deriving ()