-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter_02.hs
More file actions
56 lines (40 loc) · 784 Bytes
/
Copy pathChapter_02.hs
File metadata and controls
56 lines (40 loc) · 784 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module Chapter_02 where
-- Exercise 2.1 (*)
-- Work through the examples of chapter ”First Steps” using GHCi.
-- Copy and paste your ghci sesssion into the block comment below.
-- Exercise 2.2 (*)
-- Parenthesise the following numeric expressions:
-- 2^3*4 2*3+4*5 2+3*4^5
e_2_2_a :: Int
e_2_2_a = 2^3*4
e_2_2_b :: Int
e_2_2_b = 2*3+4*5
e_2_2_c :: Int
e_2_2_c = 2+3*4^5
{-
Prelude> 2^3*4
32
Prelude> (2^3)*4
Prelude> 2*3+4*5
26
Prelude> (2*3)+(4*5)
26
Prelude> 2+3*4^5
3074
Prelude> 2+(3*(4^5))
3074
-}
-- Excercise 2.3
{-
N = a ‘div‘ length xs
where
a = 10
xs = [1 ,2 ,3 ,4 ,5]
-}
-- Excercise 2.4
{-
Prelude| findLast xs =
Prelude| if length xs == 1 then head xs
Prelude| else findLast (tail xs)
Prelude| findLast [1,2,3,4]
-}