File tree 3 files changed +24
-6
lines changed
3 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -258,24 +258,34 @@ in Haskell and generate infinite lists of values which are only evaluated up
258
258
to the depth that it is needed.
259
259
260
260
``` haskell
261
+ -- Infinite stream of 1's
261
262
ones = 1 : ones
262
- ```
263
263
264
- ``` haskell
264
+ -- Infinite count from n
265
265
numsFrom n = n : numsFrom (n+ 1 )
266
+
267
+ -- Infinite stream of integer squares
268
+ squares = map (^ 2 ) (numsfrom 0 )
266
269
```
267
270
271
+ The function take consumes the infinite stream, consuming only the values that
272
+ are needed for the computation.
273
+
268
274
``` haskell
269
- squares = map (^ 2 ) (numsfrom 0 )
275
+ take :: Int -> [a ] -> [a ]
276
+ take n _ | n <= 0 = []
277
+ take n [] = []
278
+ take n (x: xs) = x : take (n- 1 ) xs
270
279
```
271
280
272
281
``` haskell
273
282
take 5 squares
283
+ -- [0,1,4,9,16]
274
284
```
275
285
276
286
This also admits diverging terms, called * bottoms* which have no normal form.
277
- What is unique about Haskell is that these values can be threaded around and
278
- don't diverge unless actually used .
287
+ Under lazy evaluation these values can be threaded around and will never diverge
288
+ unless actually forced .
279
289
280
290
``` haskell
281
291
bot = bot
@@ -288,6 +298,14 @@ argument is not used in the body of ``const``.
288
298
const 42 bot
289
299
```
290
300
301
+ The two bottom terms we will use frequently are used to write the scaffolding
302
+ for incomplete program.
303
+
304
+ ``` haskell
305
+ error :: String -> a
306
+ undefined :: a
307
+ ```
308
+
291
309
Higher Kinded Types
292
310
-------------------
293
311
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ MATHJAX = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_H
4
4
FLAGS = --standalone --toc --toc-depth=2 --mathjax=$(MATHJAX ) --highlight-style pygments
5
5
STYLE = css/style.css
6
6
FILTER = includes.hs
7
- TEMPLATE_HTML = page.tmpl
7
+ TEMPLATE_HTML = template.html
8
8
TEMPLATE_TEX = template.latex
9
9
10
10
SRC = $(wildcard * .md)
File renamed without changes.
You can’t perform that action at this time.
0 commit comments