-
Notifications
You must be signed in to change notification settings - Fork 0
/
types-and-typeclasses.hs
89 lines (72 loc) · 2.38 KB
/
types-and-typeclasses.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{- add m n
@takes Two integer numbers
@returns The addition of the two numbers
@examples add 1 2 == 3
add 4 5 == 9
-}
add :: Integer -> Integer -> Integer
add = \m n -> m + n
{- minus m n
@takes Two integer numbers
@returns The subtraction of the two numbers
@examples minus 2 1 == 1
minus 8 5 == 3
-}
minus :: Integer -> Integer -> Integer
minus = \m n -> m - n
{- multiply m n
@takes Two integer numbers
@returns The multiplication of the two numbers
@examples multiply 2 1 == 2
multiply 3 2 == 6
-}
multiply :: Integer -> Integer -> Integer
multiply = \m n -> m * n
{- divide m n
@takes Two numbers
@returns The division of the two numbers
@examples divide 4 2 == 2.0
divide 6 4 == 1.5
-}
divide :: Double -> Double -> Double
divide = \m n -> m / n
{- divide' m n
@takes Two integer numbers
@returns The division of the two numbers, but rounded result
@examples divide' 4 2 == 2
divide' 6 4 == 1
-}
divide' :: Integer -> Integer -> Integer
divide' = \m n -> m `div` n
{- modulus m n
@takes Two integer numbers
@returns The modulus of the two numbers
@examples modulus 2 3 == 2
modulus 2 (-3) == -1
-}
modulus :: Integer -> Integer -> Integer
modulus = \m n -> m `mod` n
{- remainder m n
@takes Two integer numbers
@returns The remainder from the quotient
@examples remainder 2 3 == 2
remainder 2 (-3) == 2
-}
remainder :: Integer -> Integer -> Integer
remainder = \m n -> m `rem` n
{- quotient m n
@takes Two integer numbers
@returns The quotient of the two numbers
@examples quotient 8 4 == 2
quotient 7 3 == 2
-}
quotient :: Integer -> Integer -> Integer
quotient = \m n -> m `quot` n
{- whoami i d s
@takes Age, height, and name of a person
@returns Generates a string from the given inputs
@examples whoami 28 172.5 "Muhit" == "Hello, Muhit! You're 28 years old and your height is 172.5 cm."
whoami 35 164.3 "Parvez" == "Hello, Parvez! You're 35 years old and your height is 164.3 cm."
-}
whoami :: Integer -> Double -> String -> String
whoami = \i d s -> "Hello, " ++ s ++ "! You're " ++ show i ++ " years old and your height is " ++ show d ++ " cm."