-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLockers.hs
29 lines (22 loc) · 860 Bytes
/
Lockers.hs
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
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" ++ show lockerNumber
++ " doesn't exist!"
Just (state, code) -> if state /= Taken
then Right code
else Left $ "Locker " ++ show lockerNumber
++ " is already taken!"
lockers :: LockerMap
lockers = Map.fromList
[ (100, (Taken, "ZD39I"))
, (101, (Free, "JAH3I"))
, (103, (Free, "IQSA9"))
, (105, (Free, "Q0TSA"))
, (109, (Taken, "893JJ"))
, (110, (Taken, "99292"))
]