-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathExample.hs
More file actions
34 lines (27 loc) · 885 Bytes
/
Example.hs
File metadata and controls
34 lines (27 loc) · 885 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 Data.HMap
-- type can be inferred.
example :: HKey x String -> HKey x1 Double -> HKey x2 Bool
-> String
example name salary female =
format a ++ "\n" ++ format b ++ "\n"
where a = insert name "Edsger" $
insert salary 4450.0 $
insert female False empty
b = insert name "Ada" $
insert salary 5000.0 $
insert female True empty
format x = x ! name ++
": salary=" ++ show (x ! salary) ++
", female=" ++ show (x ! female)
keyLocal :: String
keyLocal = withKey $ withKey $ withKey example
keyGlobal :: IO String
keyGlobal =
do name <- createKey
salary <- createKey
female <- createKey
return $ example name salary female
main = do print "local"
putStr keyLocal
print "global"
keyGlobal >>= putStr