-
Notifications
You must be signed in to change notification settings - Fork 5
/
lec01.html
632 lines (530 loc) · 21.6 KB
/
lec01.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
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Introduction to Haskell - Lecture 1</title>
<meta name="description" content="A course on the world's fastest growing functional programming language">
<meta name="author" content="Nishant Shukla">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/bootstrap-responsive.min.css">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/serif.css" id="theme">
<link href='http://fonts.googleapis.com/css?family=Ubuntu' rel='stylesheet' type='text/css'>
<style>
body {
padding-top: 30px;
padding-bottom: 40px;
}
</style>
<!-- For syntax highlighting, tomorrow-night-bright pojoaque sunburst-->
<link rel="stylesheet" href="lib/css/pojoaque.css">
<!-- If the query includes 'print-pdf', use the PDF print sheet -->
<script>
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
<script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
</head>
<body>
<script src="nav.js"></script>
<div class="reveal">
<!-- Slides begin here! -->
<div class="slides">
<section>
<section>
<h1>Introduction To Haskell</h1>
<p>Lecture 1</p>
<p>
<br>
</p>
<p>An Unexpected Journey™</p>
</section>
<section>
<h3>Using These Slides</h3>
<h4>Every slide has a secret note.</h4>
<small>
<ul>
<li>On <b>Chrome</b>: press <code>F12</code>, then click <b>Console</b></li>
<li>On <b>IE</b>: press <code>F12</code>, then click <b>Console</b></li>
<li>On <b>Firefox</b>: <code>Ctrl+Shift+k</code></li>
</ul>
</small>
<br>
<br>
<p><h3>Shortcut Keys:</h3></p>
<center>
<table width="80%">
<tr>
<td><code>↓</code>, <code>PgDn</code>, <code>n</code>, <code>j</code></td>
<td>next slide</td>
</tr>
<tr>
<td><code>↑</code>, <code>PgUp</code>, <code>p</code>, <code>k</code></td>
<td>prev slide</td>
</tr>
<tr>
<td><code>Esc</code></td>
<td>enables <code>ctrl+f</code> globally</td>
</tr>
</table>
</center>
<aside class="notes">Hi there! This is a secret lecture note. Every slide has a little blurb of text like this!</aside>
</section>
<section>
<h3>Instructor</h3>
<p><a target="_blank" href="http://shuklan.com">Nishant Shukla</a></p>
<p><small>ns4av@virginia.edu</small></p>
<br>
<h3>Watchful Guardian</h3>
<p><a target="_blank" href="http://www.cs.virginia.edu/~jwd/joomla_site/">Professor Jack Davidson</a></p>
<p><small>jwd@virginia.edu</small></p>
<aside class="notes">Email Nishant for questions on homework, class structure, and general class related things. Email Professor Davidson for anything else. If you would like to consider CS reserach, please feel free to ask Professor Davidson for advice. His areas of interest include computer security, compilers, code generation, optimization, embedded systems, and computer architecture.</aside>
</section>
<section>
<h2>Sponsored by...</h2>
<a href="http://www.student.virginia.edu/estud/"><img src="L01_files/estud.png"></a>
<aside class="notes">The Engineering Student Council at UVa helped setup and advertise this class.</aside>
</section>
<section data-state="soothe">
<h4>Quite a Turnout</h4>
<img src="L01_files/overflow.png">
<img src="L01_files/overflow2.png" class="fragment roll-in">
<img src="L01_files/overflow3b.png" class="fragment roll-in">
<aside class="notes">The class started out with just 30 open seats. Enrollment filled up quickly and we didn't expect this level of interest, so we increased enrollment to 45. Two days later the class was full again, so we finally increased enrollment to 60, doubling the original size. This class is at max capacity.</aside>
</section>
<section>
<h4><a href="https://docs.google.com/spreadsheet/viewform?formkey=dGtrcXZJUGx1QkpqVnh1WlRpTDR1VUE6MQ">Online Followers</a></h4>
<p>There are <code>1012</code> people signed up as of 1/14/13.</p>
<p>Over 121 countries, and over 50 universities:</p>
<small>
<table>
<tr>
<td width="50%">
<li>UC Berkeley</li>
<li>Cambridge</li>
<li>Georgia Tech</li>
<li>RPI</li>
<li>University of Florida</li>
<li>Oxford</li>
<li>NYU</li>
<li>University of Waterloo</li>
<li>University of Florida</li>
<li>Cornell</li>
<li>USC</li>
<li>Virginia Tech</li>
</td>
<td width="50%">
<li>MIT</li>
<li>Columbia</li>
<li>University of Maryland</li>
<li>Duke</li>
<li>Carnegie Mellon University</li>
<li>UT Dallas</li>
<li>Wesleyan University</li>
<li>Caltech</li>
<li>Imperial College</li>
<li>Brown University</li>
<li>IIT</li>
<li>... and more than 30 others</li>
</td>
</tr>
</table>
</small>
<aside class="notes">If the previous slide didn't persuade you about the popularity of Haskell I hope these will prove sufficient.</aside>
</section>
<section>
<h3>Within 2 Days of Traffic</h3>
<img src="L01_files/analytics.png">
<aside class="notes">This is further evidence of Haskell's recent growing popularity.</aside>
</section>
<section>
<a target="_blank" href="http://redmonk.com/sogrady/2012/09/12/language-rankings-9-12/"><img width="800" src="L01_files/ranking.png"></a>
<aside class="notes">This chart is from September 2012, and it shows Haskell's popularity compared to many other languages.</aside>
</section>
<section>
<img src="L01_files/langs.jpg">
<aside class="notes">Java is enterprisey, C is swift, PHP gets the job done, Ruby has a great community, and Haskell makes you think.</aside>
</section>
<section>
<h3>Syllabus</h3>
<p>
<p><a target="_blank" href="http://people.virginia.edu/~ns4av/syllabus">Find it on the class website</a></p>
<p><small>(Slides, homework, and announcements)</small></p></p>
<small><p>Meet once a week, Tuesday 5:30pm</p>
<div style="text-align: left; margin-left:30%;">
<p>Attendance: 40pts (5pts/day)</p>
<p>Homework: 30pts</p>
<p>Project: 30pts</p></small>
</div>
<br>
<div class="fragment roll-in">
<h3>Reference Text</h3>
<p><a target="_blank" href="http://book.realworldhaskell.org/">Real World Haskell</a></p>
<p><small>by Bryan O’Sullivan, Don Stewart, and John Goerzen</small></p>
<p><a target="_blank" href="http://learnyouahaskell.com/">Learn You a Haskell</a></p>
<p><small>by Miran Lipovača</small></p>
</div>
<aside class="notes">These lectures are based off 'Real World Haskell' and 'Learn You a Haskell.' For the most effective use of these lectures, you should follow along with these two books.</aside>
</section>
<!-- Add bell-curve slide -->
<section>
<h2>More Than a Language</h2>
<blockquote>I know why you're here. ...why you hardly sleep, why night after night, you sit by your computer.</blockquote>
<p>
<img width="200" src="L01_files/neo.jpg">
<br>
</p>
<aside class="notes">Where have you seen Haskell before? What made you come here?</aside>
</section>
<section>
<h3>History</h3>
<p>Alonzo Church invented <a target="_blank" href="ftp://ftp.cs.ru.nl/pub/CompMath.Found/lambda.pdf">λ-calculus</a></p>
<img src="L01_files/church.jpg">
<aside class="notes">Church made fundamental contributions to theoretical computer science. He's also known for the Church-Turing thesis, and for proving the undecidability of the Halting problem.</aside>
</section>
<section>
<p>Then John McCarthy invented <a target="_blank" href="http://www.gnu.org/software/emacs/emacs-lisp-intro/html_node/lambda.html">Lisp</a></p>
<img width="40%" src="L01_files/mccarthy.jpg">
<aside class="notes">Lisp had one of the first implementation of lambda-calculus introduced by Church. Applied computer science met theoretical computer science.</aside>
</section>
<section>
<h2>The Origin</h2>
<p>Haskell was made by a <strong>committee</strong> of really smart people to define an open standard<a target="_blank" href="http://www.haskell.org/onlinereport/preface-jfp.html">*</a></p>
<p><small>More than 20 years old</small></p>
<ul>
<li>MIT</li>
<li>Chalmers University</li>
<li>Mitre Corp</li>
<li>Victoria University of Wellington</li>
<li>Simon Fraser University</li>
<li>University of Cambridge</li>
<li>Yale University</li>
<li>University of Glasgow</li>
<li>Microsoft Research Ltd</li>
</ul>
<aside class="notes">Most research languages don't catch on. It's been more than 20 years and Haskell is still relevant today.</aside>
</section>
<section>
<p><a target="_blank" href="http://blip.tv/oreilly-open-source-convention/oscon-2007-simon-peyton-jones-a-taste-of-haskell-part-i-329701">From Simon Peyton Jones' talk at OSCON</a></p>
<img src="L01_files/lang1.png">
<aside class="notes">This diagram is from Simon Peyton Jones' slides from OSCON.</aside>
</section>
<section>
<p><a target="_blank" href="http://blip.tv/oreilly-open-source-convention/oscon-2007-simon-peyton-jones-a-taste-of-haskell-part-i-329701">From Simon Peyton Jones' talk at OSCON</a></p>
<img src="L01_files/lang2.png">
<aside class="notes">Haskell stood the test of time</aside>
</section>
<section>
<p><a target="_blank" href="http://blip.tv/oreilly-open-source-convention/oscon-2007-simon-peyton-jones-a-taste-of-haskell-part-i-329701">From Simon Peyton Jones' talk at OSCON</a></p>
<img src="L01_files/lang3.png">
<aside class="notes">There are thousands of programming languages, yet these are the ones you hear about.</aside>
</section>
<section>
<p><a target="_blank" href="http://blip.tv/oreilly-open-source-convention/oscon-2007-simon-peyton-jones-a-taste-of-haskell-part-i-329701">From Simon Peyton Jones' talk at OSCON</a></p>
<img src="L01_files/lang4.png">
<aside class="notes">Haskell is becoming more and more relevant in industry today.</aside>
</section>
<section>
<h2>Features</h2>
<div>
<br>
</div>
<div>
<ol>
<li>Purely functional</li>
<li>Statically typed</li>
<li>Lazy</li>
</ol>
</div>
<aside class="notes">These words may look confusing, but it's important you understand them in the coming slides.</aside>
</section>
<section>
<h3>1. Purely functional</h3>
<div>
<ul>
<li><strong>Every</strong> input has a corresponding output</li>
<li>
<p>
f(x) = x² + 1
</p>
</li>
<li>
<p>Powerful <strong>function compositions</strong></p>
<p>
g(x) = x - 1
</p>
<p>
g(f(x)) = x²
</p>
</li>
<li>
<p><strong>PURE</strong></p>
<p>That means <i>no side effects</i></p>
<p>A function will never modify a <i>global variable</i></p>
<p>
<p>Order doesn't matter!</p>
<p>Easy concurrency</p>
</li>
</ul>
</div>
<aside class="notes">Notice the emphasis on PURE. Haskell is not just a functional language, but it is a purely functional language!</aside>
</section>
<section data-state="soothe">
<h4>Let's be a little formal</h4>
<p>f is function from a set A to a set B.</p>
<p>f :: A → B</p>
<strong>What's the domain, codomain, and range?</strong>
<pre><code contenteditable class="haskell">
domain(f) =
codomain(f) =
range(f) ⊆
</code></pre>
<div class="fragment roll-in">
Answer:
<pre><code class="haskell">
domain(f) = A
codomain(f) = B
range(f) ⊆ B
</code></pre>
</div>
<aside class="notes">Haskell functions behave similarly to mathematical functions</aside>
</section>
<section>
<h3>Functional:</h3>
<p>Haskell, Lisp, ML, Scheme, Erlang</p>
<p><small>Focuses on the high-level <i>"what"</i></small></p>
<h3>Imperative:</h3>
<p>C++, Java, Python, Pascal</p>
<p><small>Focuses on the low-level <i>"how"</i></small></p>
<aside class="notes">Functional languages only care about 'what' is done. Imperative languages often deal with 'how' memory is managed or 'how' data is organized.</aside>
</section>
<section data-state="soothe">
<h4>What does this code do?</h4>
<pre><code>
<small>
void f(int a[], int lo, int hi)
{
int h, l, p, t;
if (lo < hi) {
l = lo;
h = hi;
p = a[hi];
do {
while ((l < h) && (a[l] <= p))
l = l+1;
while ((h > l) && (a[h] >= p))
h = h-1;
if (l < h) {
t = a[l];
a[l] = a[h];
a[h] = t;
}
} while (l < h);
a[hi] = a[l];
a[l] = p;
f( a, lo, l-1 );
f( a, l+1, hi );
}
}
</small>
</code></pre>
<small><a target="_blank" href="http://www.haskell.org/haskellwiki/Introduction">*</a></small>
<aside class="notes">This is a quicksort in C. Notice the low level array manipulations.</aside>
</section>
<section>
<h3>Sort in Haskell</h3>
<div class="fragment">
<pre><code>
<b>qsort</b> :: Ord a => [a] -> [a]
</code></pre>
</div>
<pre><code contenteditable>
<b>qsort</b> [] = []
<b>qsort</b> (p:xs) = (<b>qsort</b> lesser) ++ [p] ++ (<b>qsort</b> greater)
where
lesser = filter (< p) xs
greater = filter (>= p) xs
</code></pre>
<div class="fragment">
<p>No variable assignments, </p>
<p>No array indices, </p>
<p>No memory management!</p>
</div>
<aside class="notes">Haskell is elegant. This is the first time you've seen Haskell code in lecture, so don't worry about understanding it. Just awe at the readability of the code :)</aside>
</section>
<section>
<h3>No Side Effects</h3>
<p style="margin-right:60%">Haskell code:</p>
<pre><code>
count :: List -> Int
</code></pre>
<small>When this function runs on a List, we get back an Int. No more, no less.</small>
<br>
<br>
<p style="margin-right:65%">C++ code:</p>
<pre><code>
int count( List l ) { ... }
</pre></code>
<small>C++ however doesn't promise integrity. Maybe it's doing file IO or updating a global variable. You can't trust the code won't burn down your house.</small>
<aside class="notes">Haskell promises that your code will not burn down your house while computing the output. There are no surprises.</aside>
</section>
<section>
<h3>2. Statically Typed</h3>
<ul>
<li>f x = x² + 1</li>
<li>f :: Int → Int</li>
<li>There is never confusion about types
<p>(Bool, Int, Char, etc)</p>
</li>
<li>Strong formalism. The proof is the code.</li>
<li>If your code compiles, you're 99% done</li>
</ul>
<aside class="notes">The compiler infers the type of every function before the code is run. In other words, the compiler catches a lot of your bugs for you.</aside>
</section>
<section>
<h3>Types</h3>
<p>Every function in haskell has a Type signature.</p>
<pre><code class="haskell">
foo :: Int -> String
</pre></code>
<br>
<p>I don't know what <b>foo</b> means,</p>
<p>but I know what it does!</p>
<aside class="notes">As long as the type signature is appropriate, you can use the function anywhere. You might be thinking of methods in Java or C++ - that's a fine analogy for now.</aside>
</section>
<section>
<h3>3. Lazy</h3>
<img src="L01_files/lazy.jpg">
<aside class="notes">Haskell is lazy... in a good way!</aside>
</section>
<section>
<h4>Lazy?</h4>
<ul>
<li>Nothing is evaluated unless necessary</li>
<pre><code contenteditable>
head (sort ls)
</code></pre>
<p><small>The list will only be sorted enough to find the minimum</small></p>
<li>Allows infinite data structures</li>
<pre><code>
[1..]
</code></pre>
</ul>
<aside class="notes">This allows Haskell to be pretty fast without manipulating low-level code.</aside>
</section>
<section>
<h3>Who uses Haskell? <a target="_blank" href="http://www.haskell.org/haskellwiki/Haskell_in_industry">*</a></h3>
<table>
<tr>
<td>
<ul>
<li>AT&T <p><small>automate form processing</small></p></li>
<li>Bank of America Merril Lynch <p><small>data transformation and loading</small></p></li>
<li>Bump <p><small>Haskell-based server</small></p></li>
<li>Facebook <p><small>manipulating PHP code base</small></p></li>
</ul>
</td>
<td>
<ul>
<li>Google <p><small>internal IT infrastructure</small></p></li>
<li>MITRE <p><small>cryptographic protocol analysis</small></p></li>
<li>NVIDIA <p><small>in-house tools</small></p></li>
<li>Qualcomm, Inc <p><small>generate Lua bindings</small></p></li>
</ul>
</td>
</tr>
</table>
<aside class="notes">Technical recruiters are impressed by Haskell. By the end of these lectures you'll have the confidence to put Haskell on your resume.</aside>
</section>
<section>
<blockquote class="fragment roll-in">
Language shapes the way we think, and determines what we
can think about.
</blockquote >
<small class="fragment roll-in">- Benjamin Lee Whorf</small>
<blockquote class="fragment roll-in">
The limits of my language mean the limits of my world.
</blockquote>
<small class="fragment roll-in">- Ludwig Wittgenstein</small>
<blockquote class="fragment roll-in">
A language that doesn’t affect the way you think about programming, is not worth knowing.
</blockquote>
<small class="fragment roll-in">- Alan Perlis</small>
<p><small><a target="_blank" href="http://www.inf.ed.ac.uk/teaching/courses/inf1/fp/lectures/2012/lect01.pdf"><i>Slide from ed.ac.uk</i></a></small></p>
<aside class="notes">Takes these quotes to heart.</aside>
</section>
<section>
<h1>Homework</h1>
<h2>The Journey Begins</h2>
<ol>
<li>
<p><a target="_blank" href="http://www.haskell.org/platform/">Install Haskell</a></p>
</li>
<li>
<p>Run the interactive interpreter</p>
<pre><code>
$ ghci
Prelude>
</code></pre>
</li>
<li>
<a href="https://docs.google.com/spreadsheet/viewform?formkey=dElQVDZlN3pWT0JmVDNLQnYtOWVXYWc6MQ">Fill out this week's form</a>
</li>
</ol>
<aside class="notes">That wasn't too bad. Move on to lecture 2. We'll get to the fun stuff!</aside>
</section>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
mouseWheel: true,
rollingLinks: false,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/none
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/showdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
// { src: 'plugin/remotes/remotes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.8.3.min.js"><\/script>')</script>
<script src="js/vendor/bootstrap.min.js"></script>
<script src="js/main.js"></script>
<script>
Reveal.addEventListener( 'slidechanged', function( event ) {
// event.previousSlide, event.currentSlide, event.indexh, event.indexv
var notes = event.currentSlide.querySelector(".notes");
if(notes) {
console.info("---");
console.info(notes.innerHTML.replace(/\n\s+/g,'\n'));
}
} );
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-29747714-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>