-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlec07.html
475 lines (379 loc) · 16.2 KB
/
lec07.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Introduction to Haskell - Lecture 7</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 7</p>
<p>
<br>
</p>
<p>The Prolific Haskell Community</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('strongA').style.display = 'none';
document.getElementById('strongB').style.display = 'none';
document.getElementById('strongC').style.display = 'none';
document.getElementById('strongD').style.display = 'none';
}
function showOne(strong) {
clearAll();
document.getElementById(strong).style.display = 'block';
}
</script>
<section>
<h3>Review of Homework 6</h3>
<small><a href="lec06.html#/0/20" target="_blank">Detect whether a password is strong</a></small>
<table style="width:100%">
<tr>
<td><center><a onclick="showOne('strongA');">A</a></center></td>
<td><center><a onclick="showOne('strongB');">B</a></center></td>
<td><center><a onclick="showOne('strongC');">C</a></center></td>
<td><center><a onclick="showOne('strongD');">D</a></center></td>
</tr>
</table>
<pre id='strongA'><code class='haskell'>
-- Designed by Jamie M. Swogger
import Data.Char
import Data.List
strong x = length x > 14
&& any isLower x
&& any isUpper x
&& any isDigit x
</code></pre>
<pre id='strongB' style="display:none;"><code class='haskell'>
-- Designed by Justin Dao
-- (Similar design by Zachary A. Brown)
import Data.Set
strong :: String -> Bool
strong y
| length y < 15 = False
| intersection (fromList ['A'..'Z']) (fromList y) == fromList [] = False
| intersection (fromList ['a'..'z']) (fromList y) == fromList [] = False
| intersection (fromList ['0'..'9']) (fromList y) == fromList [] = False
| otherwise = True
</code></pre>
<pre id='strongC' style="display:none;"><code class='haskell'>
-- Designed by Christopher D. Mata
import Data.Char
strong :: String -> Bool
strong [] = False
strong x = checkLower x
&& checkUpper x
&& checkNum x
&& checkLength x
checkLower :: String -> Bool
checkLower [] = False
checkLower (x:xs)
|(isLower x) = True
|otherwise = checkLower xs
checkUpper :: String -> Bool
checkUpper [] = False
checkUpper (x:xs)
|(isUpper x) = True
|otherwise = checkUpper xs
checkNum :: String -> Bool
checkNum [] = False
checkNum (x:xs)
|(isDigit x) = True
|otherwise = checkNum xs
checkLength :: String -> Bool
checkLength [] = False
checkLength x
|(length x > 14) = True
|otherwise = False
</code></pre>
<pre id='strongD' style="display:none;"><code class='haskell'>
-- Designed by Jared Candelaria
import Data.Char
strong :: String -> Bool
strong password = all ($ password) requirements
where
requirements = [minLength 15,
any isUpper,
any isLower,
any isDigit]
minLength n str = n <= length str
</code></pre>
<aside class="notes">It's impressive how many different solutions are possible from such a simple homework assignment.</aside>
</section>
<section>
<h2><a target="_blank" href="http://www.haskell.org/haskellwiki/Category:Haskell">Haskell Wiki</a></h2>
<p>Find everything you need to know about Haskell directly from the official Wiki.</p>
<ul>
<li><a target="_blank" href="http://www.haskell.org/haskellwiki/Category:Tutorials">130 tutorials</a></li>
<li><a target="_blank" href="http://www.haskell.org/haskellwiki/Category:Mathematics">46 articles on mathematics</a></li>
<li><a target="_blank" href="http://www.haskell.org/haskellwiki/Category:FAQ">46 FAQ topics</a></li>
<li><a target="_blank" href="http://www.haskell.org/haskellwiki/Category:Community">186 articles on other Haskell communities</a></li>
</ul>
<aside class="notes">The best and most formal place to start is from the Wiki. It will lead you to almost every other resources.</aside>
</section>
<section>
<h2><a target="_blank" href="http://stackoverflow.com/questions/tagged?tagnames=haskell">StackOverflow</a></h2>
<p>More than 10,000 questions tagged</p>
<aside class="notes">StackOverflow is a popular question and answer website for finding appropriate fixes and assistance on code.</aside>
</section>
<section>
<h2><a target="_blank" href="http://www.haskell.org/haskellwiki/IRC_channel">IRC</a></h2>
<p>Server: irc.freenode.net</p>
<p>Channel: #haskell</p>
<a target="_blank" href="http://irc.netsplit.de/channels/details.php?room=%23haskell&net=freenode"><img src="L07_files/irc.png"></a>
<p>#haskell is one of the <a target="_blank" href="http://irc.netsplit.de/channels/?net=freenode">top 10 most popular channels</a> on freenode</p>
<aside class="notes">IRC is an ancient but prolific online-chat technology used for more involved discussion or rapid feedback.</aside>
</section>
<section>
<h2><a target="_blank" href="http://www.reddit.com/r/haskell/">Reddit /r/Haskell</a></h2>
<p>More than 10,000 subscribers</p>
<aside class="notes">Reddit is a popular news abrogator with a lively community.</aside>
</section>
<section>
<h1><a target="_blank" href="http://hackage.haskell.org/packages/archive/pkg-list.html">Hackage</a></h1>
<p>The <b>ultimate</b> collection of Haskell packages</p>
<aside class="notes">The official collection of supported Haskell packages is on Hackage.</aside>
</section>
<section>
<h3>Hackage + Cabal</h3>
<ul>
<p><li>You should use a tool called <a target="_blank" href="http://www.haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package">Cabal</a></li></p>
<p><li>Cabal is a command-line tool that installs packages and their dependencies</li></p>
<p><li><p>For example, try installing the HTTP library</p> <pre><code class="haskell">cabal install HTTP</code></pre></li></p>
</ul>
<aside class="notes">Cabal is meant to interact with Hackage.</aside>
</section>
<section>
<h3>Cabal</h3>
<p><small><b>C</b>ommon <b>A</b>rchitecture for <b>B</b>uilding <b>A</b>pplications and <b>L</b>ibraries</small></p>
<p>
<ul>
<li>fetches</li>
<li>configures</li>
<li>compiles</li>
<li>installs</li>
</ul>
</p>
<p><a target="_blank" href="http://www.haskell.org/haskellwiki/Cabal-Install">*</a></p>
<aside class="notes">It does most of the hard work of setting a package.</aside>
</section>
<section>
<h3>Cabal Walkthrough</h3>
<p>Let's install and use the HTTP package</p>
<ol>
<li>Refresh the list of packages</li>
<li>Install the HTTP package</li>
<li>Use it!</li>
</ol>
<aside class="notes">These three steps are often tightly coupled.</aside>
</section>
<section>
<h3>1. Refresh the list</h3>
<p>Download the most recent list of packages</p>
<pre><code class="haskell">
cabal update
</code></pre>
<aside class="notes">Make sure to always update cabal before installing a new package to get the most up to date code.</aside>
</section>
<section>
<h3>2. Install the package</h3>
<p>Find any package from <a target="_blank" href="http://hackage.haskell.org/packages/archive/pkg-list.html">Hackage</a></p>
<pre><code class="haskell">
cabal install HTTP
</code></pre>
<aside class="notes">Installation might take a minute or two.</aside>
</section>
<section>
<h3>3. Use</h3>
<p>Cabal takes care of installing the package.</p>
<p>The library can now be imported.</p>
<pre><code class="haskell">
import Network.HTTP
</code></pre>
<aside class="notes">Now you can use the installed package from your Haskell code or GHCi.</aside>
</section>
<section>
<h3>Using Network.HTTP</h3>
<p>All packages come with <a target="_blank" href="http://hackage.haskell.org/package/HTTP">documentation on Hackage</a></p>
<img src="L07_files/modules.png">
<aside class="notes">Always read the documentation, but feel free to be adventurous.</aside>
</section>
<section>
<p>Let's take a look at one of the functions in Network.HTTP</p>
<p><img src="L07_files/simpleHTTP.png"></p>
<p><code class="haskell">simpleHTTP</code> takes in a <code class="haskell">Request</code> object, and returns an IO Monad</p>
<aside class="notes">Apparently there is a Request data type in this package, and if we pass it in to this function, we can get some output back.</aside>
</section>
<section>
<h3>Try it out</h3>
<pre><code class="haskell">
Prelude> import Network.HTTP
Prelude Network.HTTP> :t simpleHTTP
simpleHTTP
:: HStream ty =>
Request ty -> IO (Network.Stream.Result (Response ty))
</code></pre>
<pre><code class="haskell">
Prelude Network.HTTP> let myRequest
= getRequest "http://duckduckgo.com"
Prelude Network.HTTP> simpleHTTP myRequest >>= getResponseBody
"<!DOCTYPE html>..."
</code></pre>
<aside class="notes">Use the getRequest function to create a variable with a Request data type. We can then pass it into `simpleHTTP` and get the output. Look carefully at the syntax above.</aside>
</section>
<section data-state="soothe">
<h2>>>=</h2>
<p>
<pre><code class="haskell">
Prelude Network.HTTP> simpleHTTP myRequest >>= getResponseBody
</code></pre>
</p>
<p>Huh... What's that?</p>
<br>
<div class="fragment roll-in">
<pre><code class="haskell">
Prelude Network.HTTP> :t (>>=)
(>>=) :: Monad m => m a -> (a -> m b) -> m b
</code></pre>
<p class="fragment roll-in"><code class="haskell">>>=</code> is called the <i>bind</i> operator</p>
</div>
<aside class="notes">We're learn more about monads in Lecture 9. Don't worry about them now.</aside>
</section>
<section>
<h1>MONADS!</h1>
<a target="_blank" href="http://www.chrisscalf.com/Sci%20Fi%20Portfolio/SciFi%20Html/Dragon%20Fire.html"><img src="L07_files/dragon.png"/></a>
<aside class="notes">Details about monads coming lecture 9!</aside>
</section>
<section>
<h2>Monad</h2>
<a target="_blank" href="http://swizec.com/blog/monads-monads-monads-monads/swizec/5206"><img src="L07_files/monads.png"/></a>
<p>Stay tuned till next time for a peek into Monads</p>
<aside class="notes">There is an aura of mysticism surrounding monads in Haskell. You're about to join me in an unforgettable journey.</aside>
</section>
<section>
<h1>Homework</h1>
<ol>
<li><a href="https://docs.google.com/forms/d/1lJ0u2mp8A_p-8d9iiGhMBey9tO8jwMHqPzv0UCKNfbI/viewform" target="_blank">Fill out this week's form!</a></li>
<li>Find the point of intersect of two lines using a package from <a href="http://hackage.haskell.org/packages/archive/pkg-list.html" target="_blank">Hackage</a></li>
<li>If you need help, address the Haskell community (Wiki, IRC, etc)</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>