-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocker.hs
More file actions
33 lines (26 loc) · 985 Bytes
/
Copy pathlocker.hs
File metadata and controls
33 lines (26 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import qualified Data.Map as Map
data LockerState = Taken | Free deriving (Show, Eq)
type Code = String
type LockerMap = Map.Map Int (LockerState, Code)
lockerLookUp :: Int -> LockerMap -> Either String Code
lockerLookUp lockerNumber map =
case Map.lookup lockerNumber map of
Nothing -> Left $ "Locker number" ++ show lockerNumber ++ "doesn't exist!"
Just (state,code) -> if state /= Taken
then Right code
else Left $ "Locker " ++ show lockerNumber ++ "iss already taken!"
lockers :: LockerMap
lockers = Map.fromList
[(100,(Taken,"ZD39I"))
,(101,(Free,"JAH3I"))
,(103,(Free,"IQSA9"))
,(105,(Free,"QOTSA"))
,(109,(Taken,"893JJ"))
,(110,(Taken,"99292"))
]
infixr 5 :-:
data List a = Empty | a :-: (List a) deriving (Show,Read,Eq,Ord)
infixr 5 .++
(.++) :: List a -> List a -> List a
Empty .++ ys = ys
(x :-: xs) .++ ys = x :-: (xs .++ ys)