-
Notifications
You must be signed in to change notification settings - Fork 28
/
2013-12-17-unordered-containers.hs
36 lines (30 loc) · 1.11 KB
/
2013-12-17-unordered-containers.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
29
30
31
32
33
34
35
36
{-# LANGUAGE DeriveGeneric #-}
import Data.HashMap.Strict
import Data.Hashable
import GHC.Generics
data Child = Child { childName :: String
, childLocation :: String
} deriving (Eq, Generic, Show)
data Priority = Please | PrettyPlease | PleasePleasePlease
deriving (Eq, Generic, Show)
data Request = Request { requestPresent :: String
, requestPriority :: Priority
} deriving (Eq, Generic, Show)
instance Hashable Child
instance Hashable Priority
instance Hashable Request
olliesWishList :: HashMap Child [Request]
olliesWishList = fromList $
let ollie = Child { childName = "ocharles"
, childLocation = "London"
}
in [(ollie, [ Request "Artisan Coffee" Please
, Request "Dependent Types in Haskell" PleasePleasePlease
, Request "Lambda Fridge Magnets" PrettyPlease
]) ]
main = do
traverseWithKey showWishList olliesWishList
where
showWishList child wants = do
putStrLn (childName child ++ " wants...")
mapM_ (putStrLn . requestPresent) wants