-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhaskell
87 lines (67 loc) · 2.15 KB
/
haskell
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
Haskell tutorial I like best: http://learnyouahaskell.com
"A gentle introduction to Haskell" is also probably good,
intended as a supplement to the original technical report.
Hmm, this appeared too, it looks quite good:
https://en.wikibooks.org/wiki/Haskell
and it references a meta-tutorial for finding a good tutorial:
https://wiki.haskell.org/Meta-tutorial
Other good references:
Good intro/overview of syntax:
https://www.fpcomplete.com/blog/2012/09/ten-things-you-should-know-about-haskell-syntax
http://www.haskellforall.com/2015/09/how-to-make-your-haskell-code-more.html
Q: What are the operator precendences?
All I know is they go from 0 (lowest) to 9 (highest),
- $ (function application) has precedence 0 (lowest),
- . (function composition) has precendence 9 (highest)
- whitespace (function application) has precedence even higher than that.
Quiz: how many different ways can you express f(g(x)), using
different combinations of parentheses, . (function composition), $ (function application)
Answer:
f(g(x)) can be expressed as:
f (g x)
f (g $ x)
f $ (g x)
f $ g x
f $ (g $ x)
f $ g $ x
(f $) (g x)
f $ ((g $) x)
(f $) ((g $) x)
f (($ x) g)
($ (g $ x)) f
($ (($ x) g)) f
(f $) (($ x) g)
($ ((g $) x)) f
-- maybe should disallow the prefix forms, there's too much blowup:
f (($) g x)
f ((($) g) x)
($) f (g x)
(($) f) (g x)
($) f (g $ x)
(($) f) (g $ x)
($) f ((g $) x)
(($) f) ((g $) x)
f $ (($) g x)
(f $) (($) g x)
f $ ((($) g) x)
(f $) ((($) g) x)
($) f (($) g x)
($) f ((($) g) x)
(($) f) (($) g x)
(($) f) ((($) g) x)
-- I probably missed some. Note that ($) f is just f, so you can
pretty much stick a ($) in front of any function even itself,
so it's not that interesting.
-- but even if we disallow the prefix form, these forms
can blow up too:
f$, g$, $(g x), $x
(f . g) x
f . g $ x
((f .) g) x
((f .) g) $ x
((. g) f) x
((. g) f) $ x
Try them out:
f = (*3)
g = (+100)
x = 1