-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExamples.hs
More file actions
73 lines (51 loc) · 1.76 KB
/
Examples.hs
File metadata and controls
73 lines (51 loc) · 1.76 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
module Revision where
-- The function to square an integer
sqrDoubleTriple :: Int -> Int
sqrDoubleTriple = triple . double . square where
square :: Int -> Int
square x = x * x
-- The function to double an integer
double :: Int -> Int
double x = x + x
triple :: Int -> Int
triple x = x*3
-- Some type synonyms
type Grade = Char
type Username = String
type ExamResult = (Username,Grade)
congradulate :: (Username,Grade) -> String
congradulate (user, grade) =
if grade == 'A'
then "well done " ++ user
else "we are Asians not Bsians!!!"
congrats :: ExamResult -> String
congrats (user, grade)
| grade == 'A' = "well done " ++ user
| grade == 'a' = "well done " ++ user
| otherwise = "we are Asians not Bsians!!!"
type Firstname = String
type Surname = String
greet :: Firstname -> Surname -> String
greet f s = "Hello " ++ f ++ " " ++ s ++ ", how's life?"
type TeamScore = (String,Int)
type MatchOutCome = (TeamScore, TeamScore)
winningTeam :: MatchOutCome -> String
winningTeam ((t1,s1), (t2,s2))
|s1 > s2 = t1
|otherwise = t2
winningTeam' :: MatchOutCome -> String--takes in a matchoutcome or two teamscore's which each are tuples of two items
winningTeam' (teamScore1, ts2) =
if (snd teamScore1)>(snd ts2) then fst teamScore1
else fst ts2
goalDifference :: MatchOutCome -> Int
goalDifference (ts1,ts2)
| (snd ts1) > (snd ts2) = (snd ts1) - (snd ts2)
| (snd ts1) < (snd ts2) = (snd ts2) - (snd ts1)
| otherwise = 0
showTeamResult :: TeamScore -> String
showTeamResult (team,score) =
"In the end " ++ team ++ " scored " ++ show score ++ " goals."
--Int variable in a string show is needed
showTeamResult' :: TeamScore -> String
showTeamResult' teamscore =
"In the end " ++ fst teamscore ++ " scored " ++ show (snd teamscore) ++ " goals."