-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeek1_Notes.html
525 lines (410 loc) · 23.4 KB
/
Week1_Notes.html
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
<!DOCTYPE html><html><head><meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="styles.css">
<title>Week1_Notes</title></head><body><article class="markdown-body"><h1>
<a id="week1-notes-of-haskell-first-steps----functional-programming-in-haskell-mooc" class="anchor" href="#week1-notes-of-haskell-first-steps----functional-programming-in-haskell-mooc" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Week1 Notes of "Haskell First Steps" -- "Functional Programming in Haskell" MOOC</h1>
<hr>
<h2>
<a id="contents" class="anchor" href="#contents" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Contents</h2>
<ul>
<li>
<a href="#haskell-basics">Haskell Basics</a>
<ul>
<li><a href="#expressions">Expressions</a></li>
<li><a href="#functions">Functions</a></li>
<li><a href="#types">Types</a></li>
<li><a href="#lists">Lists</a></li>
<li><a href="#anonymous-functions">Anonymous functions</a></li>
<li><a href="#higher-order-functions">Higher-order functions</a></li>
<li><a href="#more-notes">More notes</a></li>
</ul>
</li>
<li>
<a href="#haskell-more-basics">Haskell More Basics</a>
<ul>
<li><a href="#blocks">Blocks</a></li>
<li><a href="#conditions">Conditions</a></li>
<li><a href="#case-statement"><code>case</code> statement</a></li>
</ul>
</li>
<li>
<a href="#reduction-functions-and-lists">Reduction, Functions and Lists</a>
<ul>
<li>
<a href="#reduction">Reduction</a>
<ul>
<li><a href="#the-church-rosser-theorem">The Church-Rosser theorem</a></li>
</ul>
</li>
<li><a href="#functions-1">Functions</a></li>
<li><a href="#lists-1">Lists</a></li>
</ul>
</li>
<li><a href="#try-haskell-online">Try Haskell online</a></li>
<li><a href="#install-haskell">Install Haskell</a></li>
<li><a href="#recommended-reading">Recommended reading</a></li>
</ul>
<hr>
<p><a name="haskell-basics"></a></p>
<h2>
<a id="haskell-basics" class="anchor" href="#haskell-basics" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Haskell Basics</h2>
<p><a name="expressions"></a></p>
<h3>
<a id="expressions" class="anchor" href="#expressions" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Expressions</h3>
<ul>
<li>Haskell has no statements, only expressions!</li>
<li>Pure functional programming languages don’t have any statements — no assignments, no jumps.</li>
<li>Instead, all computation is performed by evaluating expressions.</li>
</ul>
<p><a name="functions"></a></p>
<h3>
<a id="functions" class="anchor" href="#functions" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Functions</h3>
<ul>
<li>There are no parentheses or any special keywords / operators.</li>
<li>Arguments are given after the function, separated by whitespace.</li>
<li>
<p>Syntax is fairly simple:</p>
<div class="highlight highlight-source-haskell"><pre>function_name arguments = function_body</pre></div>
</li>
<li>
<p>Example function:</p>
<div class="highlight highlight-source-haskell"><pre>hello name = <span class="pl-s"><span class="pl-pds">"</span>Hello, <span class="pl-pds">"</span></span> ++ name</pre></div>
</li>
</ul>
<p><a name="types"></a></p>
<h3>
<a id="types" class="anchor" href="#types" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Types</h3>
<ul>
<li>Haskell types are more powerful than C.</li>
<li>Function definition follows the function type declaration.</li>
<li>Type declaration is indicated by <code>::</code> and function arguments are separated by <code>-></code>.</li>
<li>
<p>Syntax is fairly simple:</p>
<div class="highlight highlight-source-haskell"><pre><span class="pl-en">function_name</span> <span class="pl-k">::</span> <span class="pl-smi">arg1_type</span> <span class="pl-k">-></span> <span class="pl-smi">arg2_type</span> <span class="pl-k">-></span> <span class="pl-smi">argn_type</span> <span class="pl-k">-></span> <span class="pl-smi">return_type</span>
function_name arguments = function_body</pre></div>
</li>
<li>
<p>Example function:</p>
<div class="highlight highlight-source-haskell"><pre><span class="pl-en">f</span> <span class="pl-k">::</span> <span class="pl-en"><span class="pl-c1">Int</span></span> <span class="pl-k">-></span> <span class="pl-en"><span class="pl-c1">Int</span></span> <span class="pl-k">-></span> <span class="pl-en"><span class="pl-c1">Int</span></span>
f x y = x*y+x+y</pre></div>
</li>
<li>
<p>More info on the example function:</p>
<ul>
<li>In this example, <code>f</code> is the function name.</li>
<li>Function arguments are of type <code>Int</code> and <code>Int</code>; while the return type is <code>Int</code>.</li>
<li>
<code>x</code> and <code>y</code> are function arguments and <code>x*y+x+y</code> is the function body.</li>
</ul>
</li>
</ul>
<p><a name="lists"></a></p>
<h3>
<a id="lists" class="anchor" href="#lists" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Lists</h3>
<ul>
<li>
<p>Python and Haskell have the same syntax for Lists.</p>
<div class="highlight highlight-source-haskell"><pre>lst = [ <span class="pl-s"><span class="pl-pds">"</span>A<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>list<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>of<span class="pl-pds">"</span></span>, <span class="pl-s"><span class="pl-pds">"</span>strings<span class="pl-pds">"</span></span>]</pre></div>
</li>
<li>
<p>To join lists, syntax in Haskell is:</p>
<div class="highlight highlight-source-haskell"><pre>lst = [<span class="pl-c1">1</span>,<span class="pl-c1">2</span>] ++ [<span class="pl-c1">3</span>,<span class="pl-c1">4</span>]</pre></div>
</li>
</ul>
<p><a name="anonymous-functions"></a></p>
<h3>
<a id="anonymous-functions" class="anchor" href="#anonymous-functions" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Anonymous functions</h3>
<ul>
<li>Anonymous functions are called <em>lambda functions</em> in Haskell, which form the basis of the language.</li>
<li>
<p>Example syntax:</p>
<div class="highlight highlight-source-haskell"><pre>f = \x y -> x*y+x+y</pre></div>
</li>
</ul>
<p><a name="higher-order-functions"></a></p>
<h3>
<a id="higher-order-functions" class="anchor" href="#higher-order-functions" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Higher-order functions</h3>
<ul>
<li>Higher-order functions are functions that operate on functions.</li>
<li>
<p>HOFs take other functions as arguments and may also return other functions.</p>
<div class="highlight highlight-source-haskell"><pre><span class="pl-c1">map</span> (\x -> x*<span class="pl-c1">2</span>) [<span class="pl-c1">1</span>..<span class="pl-c1">10</span>] <span class="pl-c">-- > 2,4,6,8,10,12,14,16,18,20]</span></pre></div>
</li>
<li>
<p>More info on the example Higher-order function:</p>
<ul>
<li>
<code>map</code> function here is a typical example for HOF.</li>
<li>The initial input list is immutable. Output of this statement is a new list is created after iterating / processing all the elements of the input list.</li>
<li>In this example, each element in the input list is doubled and returned as an element of another new list.</li>
</ul>
</li>
</ul>
<p><a name="more-notes"></a></p>
<h3>
<a id="more-notes" class="anchor" href="#more-notes" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>More notes</h3>
<ul>
<li>Precedence of function application: Function application binds tighter than anything else.</li>
<li>So <code>f x + 3</code> means <code>(f x) + 3</code> and not <code>f (x+3)</code>
<ul>
<li>Similarly, <code>sqrt 16+9</code> = <code>13</code> which is deciphered by <code>sqrt(16) + 9</code>.</li>
<li>This should be written as <code>sqrt (16+9)</code> for getting <code>5</code> as result.</li>
</ul>
</li>
<li>If an argument to a function is an expression, it should be put in parentheses.</li>
<li>
<p>Equations are not assignments</p>
<ul>
<li>A name can be given only one value.</li>
<li>Names are often called "variables", but they do not vary.</li>
<li>In Haskell variables are constant!</li>
<li>Once a value is given to a name, it can never be changed!</li>
<li>This is part of the meaning of "pure" and "no side effects".</li>
</ul>
<div class="highlight highlight-source-haskell"><pre>n = <span class="pl-c1">1</span> <span class="pl-c">-- just fine!</span>
x = <span class="pl-c1">3</span> * n <span class="pl-c">-- fine</span>
n = x <span class="pl-c">-- Wrong: can have only one definition of n</span></pre></div>
</li>
<li>
<p>It is valid to write <code>n = n + 1</code>, it is termed as an equation and not as an assignment.</p>
<ul>
<li>Haskell tries and fails to compute the result due to the recursive definition of <code>n</code> that has the property that <code>n = n + 1</code>.</li>
</ul>
</li>
<li>Think of an assignment statement as doing three things:
<ul>
<li>It evaluates the right hand side: computing a useful value.</li>
<li>It discards the value of the variable on the left hand side: destroying a value that might or might not be useful.</li>
<li>It saves the useful value of the RHS into the variable.</li>
</ul>
</li>
<li>In a pure functional language
<ul>
<li>Old values are never destroyed.</li>
<li>New useful ones just computed.</li>
<li>If the old value was truly useless, the garbage collector will reclaim its storage.</li>
</ul>
</li>
<li>
<code>4+-3</code> will fail as Haskell thinks you wanted to use a special operation '+-', so it should be written as <code>4+(-3)</code>.
<ul>
<li>Same is the case with <code>abs (-3)</code>; this should not be written as <code>abs -3</code>.</li>
</ul>
</li>
</ul>
<hr>
<p><a name="haskell-more-basics"></a></p>
<h2>
<a id="haskell-more-basics" class="anchor" href="#haskell-more-basics" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Haskell More Basics</h2>
<p><a name="blocks"></a></p>
<h3>
<a id="blocks" class="anchor" href="#blocks" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Blocks</h3>
<ul>
<li>
<p>Example code block:</p>
<div class="highlight highlight-source-haskell"><pre>roots a b c =
<span class="pl-k">let</span>
det2 = b*b-<span class="pl-c1">4</span>*a*c;
det = <span class="pl-c1">sqrt</span>(det2);
rootp = (-b + det)/a/<span class="pl-c1">2</span>;
rootm = (-b - det)/a/<span class="pl-c1">2</span>;
<span class="pl-k">in</span>
[rootm,rootp]</pre></div>
</li>
<li><p><code>let ... in ...</code> construct is an expression, so it returns a value. And there is no need for a return keyword.</p></li>
</ul>
<p><a name="conditions"></a></p>
<h3>
<a id="conditions" class="anchor" href="#conditions" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Conditions</h3>
<ul>
<li>Every <code>if</code> should have <code>then</code> and its corresponding <code>else</code> clause.</li>
<li>
<p>Again the <code>if ... then ... else ...</code> construct is an expression, so it returns a value.</p>
<div class="highlight highlight-source-haskell"><pre><span class="pl-c1">max</span> x y =
<span class="pl-k">if</span> x > y
<span class="pl-k">then</span> x
<span class="pl-k">else</span> y</pre></div>
</li>
</ul>
<p><a name="case-statement"></a></p>
<h3>
<a id="case-statement" class="anchor" href="#case-statement" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a><code>case</code> statement</h3>
<ul>
<li>A <code>case</code> statement is useful for conditions with more than two choices.</li>
<li>
<p>Can't have guards in <code>case</code> expressions.</p>
<div class="highlight highlight-source-haskell"><pre><span class="pl-k">data</span> <span class="pl-en">Color</span> <span class="pl-k">=</span> <span class="pl-ent">Red</span> | <span class="pl-ent">Blue</span> | <span class="pl-ent">Yellow</span>
color = set_color
action = <span class="pl-k">case</span> color <span class="pl-k">of</span>
<span class="pl-ent">Red</span> -> action1
<span class="pl-ent">Blue</span> -> action2
<span class="pl-ent">Yellow</span> -> action3
double zs = <span class="pl-k">case</span> zs <span class="pl-k">of</span>
<span class="pl-c1">[]</span> -> <span class="pl-c1">[]</span>
(x:xs) -> (<span class="pl-c1">2</span> * x) : (double xs)</pre></div>
</li>
</ul>
<hr>
<p><a name="reduction-functions-and-lists"></a></p>
<h2>
<a id="reduction-functions-and-lists" class="anchor" href="#reduction-functions-and-lists" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Reduction, Functions and Lists</h2>
<p><a name="reduction"></a></p>
<h3>
<a id="reduction" class="anchor" href="#reduction" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Reduction</h3>
<ul>
<li>The mechanism for executing functional programs is reduction.</li>
<li>Reduction is the process of converting an expression to a simpler form.
<ul>
<li>Conceptually, an expression is reduced by simplifying one reducible expression (called "redex") at a time.</li>
<li>Each step is called a reduction.</li>
</ul>
</li>
<li>Reduction is the sole means of execution of a functional program.</li>
<li>There are no statements, as in imperative languages; all computation is achieved purely by reducing expressions.</li>
</ul>
<p><a name="the-church-rosser-theorem"></a></p>
<h4>
<a id="the-church-rosser-theorem" class="anchor" href="#the-church-rosser-theorem" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>The Church-Rosser theorem</h4>
<ul>
<li>Every terminating reduction path gives the same result
<ul>
<li>Correctness doesn’t depend on order of evaluation.</li>
<li>The compiler (or programmer) can change the order freely to improve performance, without affecting the result.</li>
<li>Different expressions can be evaluated in parallel, without affecting the result.
<ul>
<li>As a result, functional languages are leading contenders for programming future parallel systems.</li>
</ul>
</li>
</ul>
</li>
<li>For more info, please check <a href="https://en.wikipedia.org/wiki/Church%E2%80%93Rosser_theorem">Wiki page of The Church-Rosser theorem</a>.</li>
</ul>
<p><a name="functions-1"></a></p>
<h3>
<a id="functions-1" class="anchor" href="#functions-1" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Functions</h3>
<ul>
<li>Haskell is a functional language so the function concept is essential to the language.</li>
<li>There are two fundamental operations on functions:
<ul>
<li>function definition » creating a function and</li>
<li>function application » using a function to compute a result.</li>
</ul>
</li>
</ul>
<p><a name="lists-1"></a></p>
<h3>
<a id="lists-1" class="anchor" href="#lists-1" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Lists</h3>
<ul>
<li>A list is a single value that contains several other values <em>of the <strong>same data type</strong></em>.</li>
<li>
<p>Syntax: the elements are written in square parentheses, separated by commas.</p>
<div class="highlight highlight-source-haskell"><pre>[<span class="pl-s"><span class="pl-pds">'</span>3<span class="pl-pds">'</span></span>, <span class="pl-s"><span class="pl-pds">'</span>5<span class="pl-pds">'</span></span>]
[<span class="pl-s"><span class="pl-pds">'</span>x<span class="pl-pds">'</span></span>, <span class="pl-s"><span class="pl-pds">'</span>y<span class="pl-pds">'</span></span>, <span class="pl-s"><span class="pl-pds">'</span>z<span class="pl-pds">'</span></span>]
[<span class="pl-c1">2.718</span>, <span class="pl-c1">50.0</span>, -<span class="pl-c1">1.0</span>]</pre></div>
</li>
<li>
<p>Return multiple values: Lists are useful to return multiple results from a function. <code>minmax</code> function below returns both the smaller and the larger of two numbers:</p>
<div class="highlight highlight-source-haskell"><pre>minmax = \x y -> [<span class="pl-c1">min</span> x y, <span class="pl-c1">max</span> x y]
minmax <span class="pl-c1">3</span> <span class="pl-c1">8</span> <span class="pl-c">-- > [3,8]</span>
minmax <span class="pl-c1">8</span> <span class="pl-c1">3</span> <span class="pl-c">-- > [3,8]</span></pre></div>
</li>
<li>
<p>Lazy evaluation: Elements / expressions are evaluated lazily. As long as the expression is not accessed, it is not evaluated.</p>
<div class="highlight highlight-source-haskell"><pre><span class="pl-k">let</span> xs = [<span class="pl-c1">0</span>.<span class="pl-k">.]</span> <span class="pl-c">-- doesn’t throw out of memory</span>
xs !! <span class="pl-c1">100</span> <span class="pl-c">-- > 100 -- we can access any element in the list defined</span>
<span class="pl-c1">tail</span> xs <span class="pl-c">-- This will continue to generate the numbers......</span></pre></div>
</li>
<li>
<p>Constructing lists:</p>
<ul>
<li>
<p><code>++</code>: to concat two lists</p>
<div class="highlight highlight-source-haskell"><pre>[<span class="pl-c1">23</span>, <span class="pl-c1">29</span>] ++ [<span class="pl-c1">48</span>, <span class="pl-c1">41</span>, <span class="pl-c1">44</span>] <span class="pl-c">-- > [23, 29, 48, 41, 44]</span></pre></div>
<ul>
<li>
<p>If <code>xs</code> is a list, then</p>
<div class="highlight highlight-source-haskell"><pre><span class="pl-c1">[]</span> ++ xs == xs
xs ++ <span class="pl-c1">[]</span> == xs</pre></div>
</li>
</ul>
</li>
<li>
<p><code>..</code>: sequence of items <code>[0..5]</code> gives <code>[0,1,2,3,4,5]</code></p>
<ul>
<li>Sequences are not just limited to numbers. <code>['a'..'e'] = ['a','b','c','d','e']</code> which is actually same as <code>"abcde"</code> as any String in Haskell is basically a list of characters.</li>
<li>
<p>Elements can start from any digit / character and consecutive elements can be incremented or decremented.</p>
<div class="highlight highlight-source-haskell"><pre>[<span class="pl-c1">4</span>,<span class="pl-c1">7</span>..<span class="pl-c1">20</span>] <span class="pl-c">-- > [4,7,10,13,16,19] -- each subsequent element is incremented by 3</span>
[<span class="pl-c1">10</span>,<span class="pl-c1">7</span>..(-<span class="pl-c1">13</span><span class="pl-k">)]</span> <span class="pl-c">-- > [10,7,4,1,-2,-5,-8,-11] -- each subsequent element is decremented by 3</span>
[<span class="pl-s"><span class="pl-pds">'</span>p<span class="pl-pds">'</span></span>,<span class="pl-s"><span class="pl-pds">'</span>s<span class="pl-pds">'</span></span>..<span class="pl-s"><span class="pl-pds">'</span>z<span class="pl-pds">'</span></span>] <span class="pl-c">-- > "psvy" -- for alphabets</span>
[<span class="pl-s"><span class="pl-pds">'</span>x<span class="pl-pds">'</span></span>,<span class="pl-s"><span class="pl-pds">'</span>s<span class="pl-pds">'</span></span>..<span class="pl-s"><span class="pl-pds">'</span>m<span class="pl-pds">'</span></span>] <span class="pl-c">-- > "xsn" -- alphabets decrementing</span>
[<span class="pl-s"><span class="pl-pds">'</span>$<span class="pl-pds">'</span></span>..<span class="pl-s"><span class="pl-pds">'</span>*<span class="pl-pds">'</span></span>] <span class="pl-c">-- > "$%&'()*" -- Even for special characters</span>
[(-<span class="pl-c1">6</span>)..<span class="pl-c1">2</span>] <span class="pl-c">-- > [-6,-5,-4,-3,-2,-1,0,1,2]</span></pre></div>
</li>
</ul>
</li>
<li>
<p>List comprehensions in Haskell were inspired by the mathematical notation set comprehension.</p>
<div class="highlight highlight-source-haskell"><pre>[<span class="pl-c1">3</span>*x | x <- [<span class="pl-c1">1</span>..<span class="pl-c1">10</span><span class="pl-k">]]</span> <span class="pl-c">-- > [3,6,9,12,15,18,21,24,27,30]</span></pre></div>
</li>
</ul>
</li>
<li>
<p>Operating on lists</p>
<ul>
<li>
<code>!!</code>: index a list by numbering the elements, starting with 0.
<ul>
<li>value at a specific index <code>['a'..'z'] !! 13 -- > n</code>
</li>
</ul>
</li>
<li>
<p><code>head</code>: first element of list</p>
<div class="highlight highlight-source-haskell"><pre><span class="pl-c1">head</span> [<span class="pl-c1">1</span>..<span class="pl-c1">10</span>] <span class="pl-c">-- > 1</span></pre></div>
</li>
<li>
<p><code>tail</code>: entire list except for the first element</p>
<div class="highlight highlight-source-haskell"><pre><span class="pl-c1">tail</span> [<span class="pl-c1">1</span>..<span class="pl-c1">10</span>] <span class="pl-c">-- > [2,3,4,5,6,7,8,9,10]</span>
<span class="pl-c1">tail</span> [<span class="pl-s"><span class="pl-pds">'</span>m<span class="pl-pds">'</span></span>..<span class="pl-s"><span class="pl-pds">'</span>r<span class="pl-pds">'</span></span>] <span class="pl-c">-- > "nopqr"</span></pre></div>
</li>
<li>
<p><code>init</code>: entire list except for the last element</p>
<div class="highlight highlight-source-haskell"><pre><span class="pl-c1">init</span> [<span class="pl-c1">1</span>..<span class="pl-c1">10</span>] <span class="pl-c">-- > [1,2,3,4,5,6,7,8,9]</span></pre></div>
</li>
<li>
<p><code>last</code>: last element of the list</p>
<div class="highlight highlight-source-haskell"><pre><span class="pl-c1">last</span> [<span class="pl-c1">1</span>..<span class="pl-c1">10</span>] <span class="pl-c">-- > 10</span>
<span class="pl-c1">last</span> [<span class="pl-s"><span class="pl-pds">'</span>x<span class="pl-pds">'</span></span>,<span class="pl-s"><span class="pl-pds">'</span>s<span class="pl-pds">'</span></span>..<span class="pl-s"><span class="pl-pds">'</span>m<span class="pl-pds">'</span></span>] <span class="pl-c">-- > 'm'</span></pre></div>
</li>
</ul>
</li>
</ul>
<hr>
<p><a name="try-haskell-online"></a></p>
<h2>
<a id="try-haskell-online" class="anchor" href="#try-haskell-online" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Try Haskell online</h2>
<ul>
<li>Haskell can be tried in the browser at <a href="https://www.haskellmooc.co.uk">https://www.haskellmooc.co.uk</a>.</li>
<li>This website was actually created by extending the excellent "Try Haskell" developed by Chris Done: <a href="https://tryhaskell.org/">https://tryhaskell.org/</a>.</li>
</ul>
<hr>
<p><a name="install-haskell"></a></p>
<h2>
<a id="install-haskell" class="anchor" href="#install-haskell" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Install Haskell</h2>
<ul>
<li>Haskell compiler / interpreter can be installed using <a href="https://www.haskell.org/platform">Haskell Platform</a>.</li>
</ul>
<blockquote>
<blockquote>
<p>Note: Though this course advices to install Haskell Platform, it is better to install <a href="http://www.haskellstack.org/"><code>Stack</code></a>. Please look for the installation instructions and documentation on <a href="https://docs.haskellstack.org/en/stable/README/#how-to-install">Stack website</a>.</p>
</blockquote>
</blockquote>
<hr>
<p><a name="recommended-reading"></a></p>
<h2>
<a id="recommended-reading" class="anchor" href="#recommended-reading" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Recommended reading</h2>
<ul>
<li>Please check <a href="Haskell_Learning_Resources.md"><code>Haskell Learning Resources</code></a> for detailed list of resources for learning Haskell.</li>
</ul>
<hr>
</article></body></html>