-
Notifications
You must be signed in to change notification settings - Fork 0
/
Practice.hs
36 lines (29 loc) · 979 Bytes
/
Practice.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
data Occupation = Occupation {
oName :: String
} deriving Show
data User = User {
uName :: String,
maybeOcc :: Maybe Occupation
} deriving Show
getUser :: Int -> Maybe User
getUser x = Just (User "Bob" (Just (Occupation "Builder")))
getOccupation :: User -> Maybe Occupation
getOccupation user = maybeOcc user
getUserOccupationGivenUserId :: Int -> Maybe Occupation
--getUserOccupationGivenUserId n = getUser n >>= (\user -> getOccupation user)
getUserOccupationGivenUserId n = do
user <- getUser n
occupation <- getOccupation user
return occupation
data Grade = Fail { val :: Int } |
Pass { val :: Int } |
Distinction { val :: Int } deriving Show
getGrade :: Int -> Grade
getGrade x
| x < 50 = Fail x
| x < 80 = Pass x
| otherwise = Distinction x
showGrade :: Grade -> String
showGrade (Fail x) = "Failed with " ++ show x
showGrade (Pass x) = "Passed with " ++ show x
showGrade (Distinction x) = "Distinction with " ++ show x