Introduction |
|
xv | |
So, What's Haskell? |
|
xv | |
What You Need to Dive In |
|
xvii | |
Acknowledgments |
|
xviii | |
|
|
1 | (22) |
|
|
3 | (2) |
|
|
5 | (2) |
|
|
7 | (6) |
|
|
8 | (1) |
|
|
9 | (1) |
|
|
9 | (1) |
|
|
9 | (1) |
|
|
10 | (3) |
|
|
13 | (2) |
|
|
15 | (3) |
|
|
18 | (5) |
|
|
19 | (1) |
|
|
20 | (1) |
|
Finding the Right Triangle |
|
|
21 | (2) |
|
|
23 | (12) |
|
Explicit Type Declaration |
|
|
24 | (1) |
|
|
25 | (1) |
|
|
26 | (9) |
|
|
27 | (1) |
|
|
28 | (1) |
|
|
28 | (1) |
|
|
29 | (1) |
|
|
29 | (2) |
|
|
31 | (1) |
|
|
31 | (1) |
|
|
32 | (1) |
|
|
32 | (1) |
|
|
33 | (1) |
|
Some Final Notes on Type Classes |
|
|
33 | (2) |
|
|
35 | (16) |
|
|
35 | (5) |
|
Pattern Matching with Tuples |
|
|
37 | (1) |
|
Pattern Matching with Lists and List Comprehensions |
|
|
38 | (2) |
|
|
40 | (1) |
|
|
40 | (2) |
|
|
42 | (3) |
|
|
44 | (1) |
|
Pattern Matching with where |
|
|
44 | (1) |
|
Functions in where Blocks |
|
|
45 | (1) |
|
|
45 | (3) |
|
let in List Comprehensions |
|
|
47 | (1) |
|
|
47 | (1) |
|
|
48 | (3) |
|
|
51 | (8) |
|
|
52 | (1) |
|
A Few More Recursive Functions |
|
|
53 | (3) |
|
|
53 | (1) |
|
|
54 | (1) |
|
|
55 | (1) |
|
|
55 | (1) |
|
|
55 | (1) |
|
|
56 | (1) |
|
|
56 | (2) |
|
|
56 | (1) |
|
|
57 | (1) |
|
|
58 | (1) |
|
|
59 | (28) |
|
|
59 | (4) |
|
|
62 | (1) |
|
|
63 | (1) |
|
Some Higher-Orderism Is in Order |
|
|
63 | (3) |
|
|
64 | (1) |
|
|
65 | (1) |
|
The Functional Programmer's Toolbox |
|
|
66 | (5) |
|
|
66 | (1) |
|
|
67 | (1) |
|
More Examples of map and filter |
|
|
68 | (2) |
|
Mapping Functions with Multiple Parameters |
|
|
70 | (1) |
|
|
71 | (2) |
|
|
73 | (7) |
|
|
74 | (1) |
|
|
75 | (1) |
|
The foldl and foldr 1 Functions |
|
|
76 | (1) |
|
|
76 | (1) |
|
Another Way to Look at Folds |
|
|
77 | (1) |
|
|
78 | (1) |
|
|
79 | (1) |
|
Function Application with $ |
|
|
80 | (2) |
|
|
82 | (5) |
|
Function Composition with Multiple Parameters |
|
|
83 | (1) |
|
|
84 | (3) |
|
|
87 | (22) |
|
|
88 | (2) |
|
Solving Problems with Module Functions |
|
|
90 | (8) |
|
|
90 | (1) |
|
|
91 | (1) |
|
|
92 | (2) |
|
|
94 | (1) |
|
Let's Find Some Cool Numbers |
|
|
95 | (3) |
|
|
98 | (6) |
|
Almost As Good: Association Lists |
|
|
98 | (2) |
|
|
100 | (4) |
|
|
104 | (5) |
|
|
104 | (2) |
|
|
106 | (3) |
|
7 Making Our Own Types And Type Classes |
|
|
109 | (44) |
|
|
109 | (1) |
|
|
110 | (4) |
|
Improving Shape with the Point Data Type |
|
|
112 | (1) |
|
Exporting Our Shapes in a Module |
|
|
113 | (1) |
|
|
114 | (3) |
|
|
117 | (5) |
|
Should We Parameterize Our Car? |
|
|
119 | (2) |
|
|
121 | (1) |
|
|
122 | (5) |
|
|
123 | (1) |
|
|
124 | (1) |
|
|
125 | (1) |
|
|
126 | (1) |
|
|
127 | (5) |
|
Making Our Phonebook Prettier |
|
|
128 | (1) |
|
Parameterizing Type Synonyms |
|
|
129 | (1) |
|
|
130 | (2) |
|
Recursive Data Structures |
|
|
132 | (6) |
|
|
133 | (2) |
|
|
135 | (3) |
|
|
138 | (5) |
|
|
138 | (1) |
|
A Traffic Light Data Type |
|
|
139 | (1) |
|
|
140 | (1) |
|
Parameterized Types As Instances of Type Classes |
|
|
141 | (2) |
|
|
143 | (3) |
|
|
146 | (4) |
|
|
147 | (1) |
|
|
148 | (1) |
|
|
149 | (1) |
|
|
150 | (3) |
|
|
153 | (16) |
|
Separating the Pure from the Impure |
|
|
153 | (1) |
|
|
154 | (2) |
|
Gluing I/O Actions Together |
|
|
156 | (5) |
|
Using let Inside I/O Actions |
|
|
158 | (1) |
|
|
159 | (2) |
|
Some Useful I/O Functions |
|
|
161 | (6) |
|
|
161 | (1) |
|
|
162 | (1) |
|
|
162 | (1) |
|
|
163 | (1) |
|
|
164 | (1) |
|
|
165 | (1) |
|
|
165 | (1) |
|
|
166 | (1) |
|
|
167 | (2) |
|
9 More Input And More Output |
|
|
169 | (34) |
|
|
169 | (6) |
|
|
170 | (1) |
|
Getting Strings from Input Streams |
|
|
171 | (2) |
|
|
173 | (2) |
|
Reading and Writing Files |
|
|
175 | (5) |
|
Using the withFile Function |
|
|
177 | (1) |
|
|
178 | (1) |
|
|
179 | (1) |
|
|
180 | (4) |
|
|
181 | (2) |
|
|
183 | (1) |
|
|
184 | (1) |
|
More Fun with To-Do Lists |
|
|
185 | (5) |
|
|
186 | (4) |
|
|
190 | (1) |
|
|
190 | (8) |
|
|
193 | (1) |
|
|
194 | (1) |
|
|
195 | (3) |
|
|
198 | (5) |
|
Strict and Lazy Bytestrings |
|
|
199 | (2) |
|
Copying Files with Bytestrings |
|
|
201 | (2) |
|
10 Functionally Solving Problems |
|
|
203 | (14) |
|
Reverse Polish Notation Calculator |
|
|
203 | (5) |
|
Calculating RPN Expressions |
|
|
204 | (1) |
|
|
205 | (2) |
|
|
207 | (1) |
|
|
208 | (9) |
|
Calculating the Quickest Path |
|
|
209 | (2) |
|
Representing the Road System in Haskell |
|
|
211 | (1) |
|
Writing the Optimal Path Function |
|
|
212 | (3) |
|
Getting a Road System from the Input |
|
|
215 | (2) |
|
|
217 | (26) |
|
|
218 | (5) |
|
|
218 | (2) |
|
|
220 | (3) |
|
|
223 | (4) |
|
|
223 | (1) |
|
|
224 | (1) |
|
|
225 | (2) |
|
Using Applicative Functors |
|
|
227 | (11) |
|
|
228 | (1) |
|
Maybe the Applicative Functor |
|
|
229 | (1) |
|
|
230 | (2) |
|
|
232 | (2) |
|
IO Is An Applicative Functor, Too |
|
|
234 | (1) |
|
Functions As Applicatives |
|
|
235 | (2) |
|
|
237 | (1) |
|
|
238 | (1) |
|
Useful Functions for Applicatives |
|
|
238 | (5) |
|
|
243 | (24) |
|
Wrapping an Existing Type into a New Type |
|
|
243 | (7) |
|
Using newtype to Make Type Class Instances |
|
|
246 | (1) |
|
|
247 | (2) |
|
type vs. newtype vs. data |
|
|
249 | (1) |
|
|
250 | (3) |
|
|
252 | (1) |
|
|
253 | (1) |
|
|
253 | (9) |
|
|
253 | (1) |
|
|
254 | (2) |
|
|
256 | (1) |
|
|
257 | (3) |
|
|
260 | (2) |
|
|
262 | (5) |
|
|
267 | (30) |
|
Upgrading Our Applicative Functors |
|
|
267 | (2) |
|
Getting Your Feet Wet with Maybe |
|
|
269 | (3) |
|
|
272 | (2) |
|
|
274 | (6) |
|
|
274 | (2) |
|
|
276 | (2) |
|
|
278 | (2) |
|
|
280 | (5) |
|
|
282 | (1) |
|
|
282 | (2) |
|
Pattern Matching and Failure |
|
|
284 | (1) |
|
|
285 | (7) |
|
do Notation and List Comprehensions |
|
|
288 | (1) |
|
MonadPlus and the guard Function |
|
|
288 | (2) |
|
|
290 | (2) |
|
|
292 | (5) |
|
|
293 | (1) |
|
|
294 | (1) |
|
|
294 | (3) |
|
|
297 | (46) |
|
Writer? I Hardly Knew Herl |
|
|
298 | (12) |
|
|
300 | (2) |
|
|
302 | (1) |
|
Using do Notation with Writer |
|
|
303 | (1) |
|
Adding Logging to Programs |
|
|
304 | (2) |
|
Inefficient List Construction |
|
|
306 | (1) |
|
|
307 | (2) |
|
|
309 | (1) |
|
Reader? Ugh, Not This Joke Again |
|
|
310 | (1) |
|
|
311 | (2) |
|
|
312 | (1) |
|
Tasteful Stateful Computations |
|
|
313 | (8) |
|
|
314 | (1) |
|
|
314 | (2) |
|
|
316 | (2) |
|
Getting and Setting State |
|
|
318 | (2) |
|
Randomness and the State Monad |
|
|
320 | (1) |
|
|
321 | (2) |
|
Some Useful Monadic Functions |
|
|
323 | (9) |
|
|
323 | (3) |
|
|
326 | (2) |
|
|
328 | (3) |
|
|
331 | (1) |
|
Making a Safe RPN Calculator |
|
|
332 | (3) |
|
Composing Monadic Functions |
|
|
335 | (1) |
|
|
336 | (7) |
|
|
343 | (20) |
|
|
344 | (8) |
|
|
346 | (2) |
|
|
348 | (2) |
|
Manipulating Trees Under Focus |
|
|
350 | (1) |
|
Going Straight to the Top, Where the Air Is Fresh and Clean! |
|
|
351 | (1) |
|
|
352 | (1) |
|
|
353 | (5) |
|
Making a Zipper for Our Filesystem |
|
|
355 | (2) |
|
Manipulating a Filesystem |
|
|
357 | (1) |
|
|
358 | (2) |
|
|
360 | (3) |
Index |
|
363 | |