-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChapter2.hs
More file actions
103 lines (82 loc) · 1.43 KB
/
Chapter2.hs
File metadata and controls
103 lines (82 loc) · 1.43 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
module Chapter2 where
-- discuss Karate Kid Movie
-- discuss Prelude
-- repl: 2 + 3
-- repl: 2 - 3
-- repl: 2 * 3
-- repl: 7 `div` 2
-- repl: 2 ^ 3
-- emdas
-- repl: head [1, 2, 3, 4, 5]
-- repl: tail [1, 2, 3, 4, 5]
-- repl: [1, 2, 3, 4, 5] !! 2
-- repl: take 3 [1, 2, 3, 4, 5]
-- repl: drop 3 [1, 2, 3, 4, 5]
-- repl: length [1, 2, 3, 4, 5]
-- repl: sum [1, 2, 3, 4, 5]
-- repl: product [1, 2, 3, 4, 5]
-- repl: [1, 2, 3] ++ [4, 5]
-- repl: reverse [1, 2, 3, 4, 5]
-- repl: 1 `div` 0
-- repl: head []
-- discuss function application with accordance to mathematics
-- f(a, b) + c d
-- f a b + c * d
-- femdas
-- f a + b means (f a) + b
{-
Math
f(x)
f(x, y)
f(g(x))
f(x, g(y))
f(x)g(y)
Haskell
f x
f x y
f (g x)
f x (g y)
f x * g y
also compare with other languages
discuss working with a text editor and ghci
discuss common ghci commands
:load <name> or :l <name>
:reload or :r
:edit <name> :e <name>
:type <name> :t <name>
:?
:quit or :q
discuss naming requirements
functions starts with lowercase letters
but can be follwed by zero or more letters (upper and lower),
digits, underscores and quotes
you cannot use keywords as function names or values
case
class
data
default
deriving
do
else
if
import
in
infix
infixl
infixr
instance
let
module
newtype
of
then
type
where
discuss layout rule
-}
a = b + c
where b = 1
c = 2
d = a * 2
-- discuss comments (single line and multi line)
-- dicuss book, installation and fpcomplete