-
Notifications
You must be signed in to change notification settings - Fork 5
/
lec03.html
795 lines (639 loc) · 24.1 KB
/
lec03.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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Introduction to Haskell - Lecture 3</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 -->
<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>
<script>
function toggleElements(one, two) {
document.getElementById(one).style.display = 'none';
document.getElementById(two).style.display = 'block';
}
</script>
<div class="reveal">
<!-- Slides begin here! -->
<div class="slides">
<section>
<section>
<h1>Introduction To Haskell</h1>
<p>Lecture 3</p>
<p>
<br>
</p>
<p>types :: type1 → type2</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>
<script>
function clearAll() {
document.getElementById('facA').style.display = 'none';
document.getElementById('facB').style.display = 'none';
document.getElementById('facC').style.display = 'none';
document.getElementById('facD').style.display = 'none';
document.getElementById('facE').style.display = 'none';
document.getElementById('facF').style.display = 'none';
document.getElementById('facG').style.display = 'none';
document.getElementById('facH').style.display = 'none';
document.getElementById('facI').style.display = 'none';
document.getElementById('facJ').style.display = 'none';
}
function showOne(fac) {
clearAll();
document.getElementById(fac).style.display = 'block';
}
</script>
<section>
<h3>Haskell Programming</h3>
<ul>
<li>Code lives in a file with a .hs extension</li>
<br>
<li>Open the file with GHCi
<table>
<tr>
<td>
<small>Run it from the terminal</small>
<pre><code class="haskell">
$ ghci myfile.hs
</code></pre>
</td>
<td>
<small>Or run ghci, then load the file</small>
<pre><code class="haskell">
$ ghci
Prelude> :load myfile
</code></pre>
</td>
</tr>
</table>
</li>
<li>Call your function through ghci</li>
</ul>
<aside class="notes">This is just a review.</aside>
</section>
<section>
<h2>Previous Homework</h2>
<small><q><a href="./lec02.html#/0/22" target="_blank">Implement factorial</a></q></small>
<table style="width:100%">
<tr>
<td><a onclick="showOne('facA');">A</a></td>
<td><a onclick="showOne('facB');">B</a></td>
<td><a onclick="showOne('facC');">C</a></td>
<td><a onclick="showOne('facD');">D</a></td>
<td><a onclick="showOne('facE');">E</a></td>
<td><a onclick="showOne('facF');">F</a></td>
<td><a onclick="showOne('facG');">G</a></td>
<td><a onclick="showOne('facH');">H</a></td>
<td><a onclick="showOne('facI');">I</a></td>
<td><a onclick="showOne('facJ');">J</a></td>
<td><a target="_blank" href="http://willamette.edu/~fruehr/haskell/evolution.html">...</a></td>
</tr>
</table>
<pre id='facA'><code>
-- Most popular solution
facA n = if n > 1
then n * facA(n-1)
else n
</code></pre>
<pre id='facB' style="display:none;"><code>
-- Right tools for the right job
facB n = product [1..n]
</code></pre>
<pre id='facC' style="display:none;"><code>
-- Oh, you.
facC n = foldr (*) 1 [1..n]
</code></pre>
<pre id='facD' style="display:none;"><code>
-- Sophomore Haskell programmer
-- (studied Scheme as a freshman)
-- http://willamette.edu/~fruehr/haskell/evolution.html
facD = (\(n) ->
(if ((==) n 0)
then 1
else ((*) n (facD ((-) n 1)))))
</code></pre>
<pre id='facE' style="display:none;"><code>
-- Memoizing Haskell programmer
-- http://willamette.edu/~fruehr/haskell/evolution.html
facs = scanl (*) 1 [1..]
facE n = facs !! n
</code></pre>
<pre id='facF' style="display:none;"><code>
-- Iterative Haskell programmer
-- (former Pascal programmer)
-- http://willamette.edu/~fruehr/haskell/evolution.html
facF n = result (for init next done)
where init = (0,1)
next (i,m) = (i+1, m * (i+1))
done (i,_) = i==n
result (_,m) = m
for i n d = until d n i
</code></pre>
<pre id='facG' style="display:none;"><code>
-- Continuation-passing Haskell programmer
-- http://willamette.edu/~fruehr/haskell/evolution.html
facCps k 0 = k 1
facCps k n = facCps (k . (n *)) (n-1)
facG = facCps id
</code></pre>
<pre id='facH' style="display:none;"><code>
-- Boy Scout Haskell programmer
-- http://willamette.edu/~fruehr/haskell/evolution.html
y f = f (y f)
facH = y (\f n -> if (n==0) then 1 else n * f (n-1))
</code></pre>
<pre id='facI' style="display:none;"><code>
-- Combinatory Haskell programmer
-- http://willamette.edu/~fruehr/haskell/evolution.html
s f g x = f x (g x)
k x y = x
b f g x = f (g x)
c f g x = f x g
y f = f (y f)
cond p f g x = if p x then f x else g x
facI = y (b (cond ((==) 0) (k 1)) (b (s (*)) (c b pred)))
</code></pre>
<pre id='facJ' style="display:none;"><code>
-- List-encoding Haskell programmer
-- (prefers to count in unary)
-- http://willamette.edu/~fruehr/haskell/evolution.html
arb = ()
listenc n = replicate n arb
listprj f = length . f . listenc
listprod xs ys = [ i (x,y) | x<-xs, y<-ys ]
where i _ = arb
facl [] = listenc 1
facl n@(_:pred) = listprod n (facl pred)
facJ = listprj facl
</code></pre>
<aside class="notes">There's always multiple ways to implement any function.</aside>
</section>
<section>
<h3>Types</h3>
<ul>
<li class="fragment"><p><code class="haskell">Bool</code> = False | True</p></li>
<li class="fragment"><p><code class="haskell">Char</code> = 'a' | 'b' | ... | 'A' | 'B' | ...</p></li>
<li class="fragment"><p><code class="haskell">Int</code> = -2<sup>31</sup> | ... | -1 | 0 | 1 | ... | 2<sup>31</sup>-1</p></li>
<li class="fragment"><p><code class="haskell">Integer</code></p></li>
<li class="fragment"><p><code class="haskell">Double</code></p></li>
</ul>
<br>
<br>
<p>Types always start with a capital letter</p>
<aside class="notes">Think of these almost as Java types (int, String, etc).</aside>
</section>
<section>
<h2>Everything has a Type</h2>
<p>Haskell secretly infers that <code class="haskell">True</code> is a <code class="haskell">Bool</code>.</p>
<pre><code class="haskell">
Prelude> :type True
True :: Bool
</code></pre>
<br>
<div class="fragment roll-in">
<p>You can also explicitly use a type.</p>
<pre><code class="haskell">
Prelude> 3 :: Int
3
Prelude> 3 :: Double
3.0
</code></pre>
</div>
<aside class="notes">'::' is pronounced 'has the type of'</aside>
</section>
<section>
<h3>Yes, Functions have a Type</h3>
<div class="fragment roll-in">
<pre><code class="haskell">
Prelude> head [1,2,3,4]
1
Prelude> :type head
head :: [a] -> a
</code></pre>
<small><code>head</code> has the type <i>List of <code class="haskell">a</code>'s</i> to just <i><code class="haskell">a</code></i></small>
</div>
<div class="fragment roll-in">
<pre><code class="haskell">
Prelude> fst ("left", "right")
"left"
Prelude> :type fst
fst :: (a, b) -> a
</code></pre>
<small>fst has the type <i>tuple of <code class="haskell">a</code> and <code class="haskell">b</code></i> to just <i><code class="haskell">a</code></i></small>
</div>
<aside class="notes">'a' and 'b' here are called Type variables.</aside>
</section>
<!--
Strong; bugs are usually caught when compiling. Strings can't accidentally be treated as Ints.
Static; the compiler knows the type of every value
It Haskell code compiles, you can bet there won't be any type errors
If you've ever been surprised that your long piece of code worked on the first run,
then Haskell will spoil you.
Type inference; The compiler deduces what you mean, without surprises
talk about variables "Just what is a variable, anyway?"
-->
<section>
<h3>Like a Jigsaw Puzzle</h3>
<small>Analogy from <a target="_blank" href="http://book.realworldhaskell.org/read/types-and-functions.html"><i>Real World Haskell</i></a></small>
<p><small>"if a piece has the wrong shape, it simply won't fit"</small></p>
<table border="1">
<tr>
<td>Haskell</td>
<td>Python<a target="_blank" href="http://en.wikipedia.org/wiki/Duck_typing">*</a></td>
</tr>
<tr>
<td><img src="L03_files/zoidberg1.png"></td>
<td><img src="L03_files/zoidberg2.png"></td>
</tr>
</table>
<aside class="notes">Bugs are usually caught at compile-time. The compiler knows the type of every value, so there is never ambiguity.</aside>
</section>
<section data-state="soothe">
<p><small>What should be the <b>type declaration</b> for <code class="haskell">fac</code>?</small>
<small>
<a onclick="toggleElements('b', 'a');">(clear answer)</a>
<a onclick="toggleElements('a', 'b');">(show answer)</a>
</small>
</p>
<pre id="a"><code class="haskell" contenteditable>
fac n = product [1..n]
</code></pre>
<pre id="b" style="display:none;"><code class="haskell">
fac :: Integer -> Integer
fac n = product [1..n]
</code></pre>
<br>
<div class="fragment roll-in">
<p><small>What's the <b>type declaration</b> for <code class="haskell">&&</code> ?</small>
<small>
<a onclick="toggleElements('d', 'c');">(clear answer)</a>
<a onclick="toggleElements('c', 'd');">(show answer)</a>
</small>
</p>
<pre id="c"><code class="haskell" contenteditable>
(&&) ::
</code></pre>
<pre id="d" style="display:none;"><code class="haskell">
(&&) :: Bool -> Bool -> Bool
</code></pre>
</div>
<br>
<div class="fragment roll-in">
<p><small>How about <code class="haskell">:</code> ?</small>
<small>
<a onclick="toggleElements('f', 'e');">(clear answer)</a>
<a onclick="toggleElements('e', 'f');">(show answer)</a>
</small>
</p>
<pre id="e"><code class="haskell" contenteditable>
Prelude> 0:[1,2,3]
[0,1,2,3]
Prelude> :type (:)
</code></pre>
<pre id="f" style="display:none;"><code class="haskell">
Prelude> 0:[1,2,3]
[0,1,2,3]
Prelude> :type (:)
(:) :: a -> [a] -> [a]
</code></pre>
</div>
<aside class="notes">In GHCi, you can do ':type f' to find the type of function 'f'</aside>
</section>
<section>
<h2>Google Tech Talk</h2>
<p><small>(8:00 to 9:22)</small></p>
<iframe width="672" height="504" src="http://www.youtube.com/embed/b9FagOVqxmI?start=480&end=562" frameborder="0" allowfullscreen></iframe>
<aside class="notes">The Haskell compiler tries to infer the type for you. If ambiguous, the programmer must specify the Type explicitly.</aside>
</section>
<section>
<h2>Typeclass</h2>
<p>A Typeclass lets you generalize a function.</p>
<small><p>For example, the less-than sign can be used multiple ways.</p></small>
<ul>
<li><code class="haskell">10 < 20</code></li>
<li><code class="haskell">'a' < 'b'</code></li>
<li><code class="haskell">"aardvark" < "zzz"</code></li>
<li><code class="haskell">[6,2,4] < [6,3,8]</code></li>
</ul>
<aside class="notes">This is a type of polymorphism.</aside>
</section>
<section>
<h2>The <code class="haskell">Ord</code> Typeclass</h2>
<p>is used for things with total order</p>
<pre id="g"><code class="haskell" contenteditable>
Prelude> :type (<)
</code></pre>
<pre id="h" style="display:none;"><code class="haskell" contenteditable>
Prelude> :type (<)
(<) :: a -> a -> Bool
</code></pre>
<pre id="i" style="display:none;"><code class="haskell">
Prelude> :type (<)
(<) :: Ord a => a -> a -> Bool
</code></pre>
<span style="font-size:12px;">
<a onclick="toggleElements('h', 'g');toggleElements('i', 'g');">(clear answer)</a>
<a onclick="toggleElements('g', 'h');toggleElements('i', 'h');">(show incorrect answer)</a>
<a onclick="toggleElements('g', 'i');toggleElements('h', 'i');">(show answer)</a>
</span>
<aside class="notes">Less-than is a function that that takes two comparable things, and outputs a Bool.</aside>
</section>
<section>
<h3>Similar to Interfaces</h3>
<p><small>Remember them from Java?</small></p>
<pre><code class="haskell">
public class NumberUsedByLessThanSign implements Comparable {
...
}
</code></pre>
<aside class="notes">A Typeclass gives a Type some property. For example, both Int and String are comparable, so they both has the type class of Ord.</aside>
</section>
<section>
<h3>Other Typeclasses</h3>
<ul>
<li><code class="haskell">Show</code> - representable as a string
<pre><code class="haskell">
Prelude> show 42
"42"
</code></pre>
</li>
<li><code class="haskell">Enum</code> - enumerable in a list
<pre><code class="haskell">
Prelude> ['R'..'t']
"RSTUVWXYZ[\\]^_`abcdefghijklmnopqrst"
</code></pre>
</li>
<li><code class="haskell">Num</code> - usable as a number
<pre><code class="haskell">
Prelude> 5.2 * 2.5
13.0
</code></pre>
</li>
</ul>
<aside class="notes">42 has the Show Typeclass because we can print it out as a String. Characters have the Enum Typeclass because we can put them in order of ASCII code. Numbers have the Num Typeclass because they can do number-like operations.</aside>
</section>
<section>
<h3>Have you noticed?</h3>
<p>Functions with multiple arguments look funny.</p>
<div class="fragment">
<p>The <code class="haskell">take</code> function has <b>two arguments</b>:</p>
<ul>
<li>an integer, <code class="haskell">n</code></li>
<li>a list, <code class="haskell">ls</code></li>
</ul>
<p>and it produces the first <code class="haskell">n</code> elements of <code class="haskell">ls</code></p>
<pre><code class="haskell">
Prelude> take 5 [1..]
[1,2,3,4,5]
</code></pre>
<div class="fragment roll-in">
<p>The type declaration is</p>
<pre><code class="haskell">
Prelude> :type take
take :: Int -> [a] -> [a]
</code></pre>
<p class="fragment roll-in">Weird...</p>
</div>
</div>
<aside class="notes">It appears like this function has one argument 'Int', and one output '[a]' with something in-between.</aside>
</section>
<section>
<h2>The Concept of <a href="http://www.haskell.org/haskellwiki/Currying" target="_blank">Currying</a></h2>
<p>All Haskell functions take only one argument</p>
<aside class="notes">Take a moment to think about that statement.</aside>
</section>
<section>
<img src="L03_files/grumpycat.png">
<aside class="notes">You mind is about to be blown.</aside>
</section>
<section>
<h3>A Closer Look</h3>
<p>at the <code class="haskell">take</code> function:</p>
<pre><code class="haskell">
take :: Int -> [a] -> [a]
</code></pre>
<br>
<div class="fragment roll-in">
<p>The <code class="haskell">-></code> operator is <i>right-associative</i></p>
<pre><code class="haskell">
take :: Int -> ([a] -> [a])
</code></pre>
<p><code class="haskell">take</code> actually has type of <i>Int to a function</i></p>
</div>
<aside class="notes">So technically, 'take' has just one argument (something of type Int)</aside>
</section>
<section>
<h3>Partial Applications</h3>
<p>Every function technically has one argument.</p>
<p>Actually, this is really cool!</p>
<pre><code class="haskell">
Prelude> :type take
take :: Int -> [a] -> [a]
Prelude> let takeFive = take 5
Prelude> :type takeFive
takeFive :: [a] -> [a]
Prelude> takeFive [1..]
[1,2,3,4,5]
</pre></code>
<aside class="notes">Try it out yourself.</aside>
</section>
<section>
<h2>Functional and Pure</h2>
<p class="fragment roll-in">A function only depends on its aguments.</p>
<p class="fragment roll-in">A type declaration is a strong promise.</p>
<p class="fragment roll-in">Focus on <i>what</i> is done, not <i>how</i>.</p>
<p class="fragment roll-in">Inherently modular</p>
<p class="fragment roll-in">Elegant</p>
<aside class="notes">I hope you're beginning to see why Haskell is a little different.</aside>
</section>
<section data-state="soothe">
<h3>Get Our Hands Dirty</h3>
<p>Create <code class="haskell">mycode.hs</code> and write a function called <code class="haskell">zipTogether</code></p>
<pre id="j"><code class="haskell" contenteditable>
-- mycode.hs
-- |The 'zipTogether' function binds together two lists.
zipTogether :: [a] -> [b] -> [(a,b)]
</code></pre>
<pre id="k" style="display:none;"><code class="haskell" contenteditable>
-- mycode.hs
-- |The 'zipTogether' function binds together two lists.
zipTogether :: [a] -> [b] -> [(a,b)]
zipTogether [] [] = []
zipTogether [] ys = []
zipTogether xs [] = []
zipTogether xs ys = (head xs, head ys):
(zipTogether (tail xs) (tail ys))
</code></pre>
<pre id="l" style="display:none;"><code class="haskell" contenteditable>
-- mycode.hs
-- |The 'zipTogether' function binds together two lists.
zipTogether :: [a] -> [b] -> [(a,b)]
zipTogether [] [] = []
zipTogether [] ys = []
zipTogether xs [] = []
zipTogether (x:xs) (y:ys) = (x,y) : zipTogether xs ys
</code></pre>
<span style="font-size:12px;">
<a onclick="toggleElements('k', 'j');toggleElements('l', 'j');">(clear answer)</a>
<a onclick="toggleElements('j', 'k');toggleElements('l', 'k');">(show answer 1)</a>
<a onclick="toggleElements('j', 'l');toggleElements('k', 'l');">(show answer 2)</a>
</span>
<br>
<p>Expected output:</p>
<pre><code class="haskell" contenteditable>
Prelude> zipTogether [1,2,3] "abc"
[(1,'a'),(2,'b'),(3,'c')]
</code></pre>
<small class="fragment roll-in">by the way, Haskell comes with <code class="haskell">zip</code></small>
<aside class="notes">Zipping is actually used a lot in functional programming. Think of it as zipping together the x-y axes of a graph to plot points.</aside>
</section>
<section>
<h1>Homework</h1>
<h2></h2>
<ol>
<li>
Write a Caesar Cipher function called <code class="haskell">cipher</code>
<div id="p">
<pre><code class="haskell" contenteditable>
cipher :: [Char] -> Int -> [Char]
</code></pre>
<pre><code class="haskell" contenteditable>
Prelude> cipher "hello" 13
"uryyb"
</code></pre>
</div>
<div id="m" style="display:none;">
<small>Are you sure?</small>
<span style="font-size:12px;">
<p><a onclick="toggleElements('m', 'n');toggleElements('o', 'n');toggleElements('p','n');">(please show hint!)</a></p>
</span>
</div>
<div id="n" style="display:none;">
<pre><code class="haskell">
cipher :: [Char] -> Int -> [Char]
cipher [] _ = []
cipher (s:ss) n = (rotate s n) : (cipher ss n)
rotate :: Char -> Int -> Char
</pre></code>
<span style="font-size:12px;">
<p> Now define this 'rotate' function</p>
</span>
</div>
<span id="o" style="font-size:12px;">
<a onclick="toggleElements('n', 'm');toggleElements('o', 'm');">(show hint)</a>
</span>
</li>
<li>
<p>Bonus points for a cool solution!</p>
</li>
<li>
<p>Submit this week's <a href="https://docs.google.com/spreadsheet/viewform?formkey=dC1VWVo4OXFXcWZqTjEzUnoySDRLV1E6MQ">homework form!</a></p>
</li>
</ol>
</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>