About the Author |
|
xv | |
About the Technical Reviewer |
|
xvii | |
Acknowledgments |
|
xix | |
Introduction |
|
xxi | |
|
|
1 | (182) |
|
Chapter 1 Going Functional |
|
|
3 | (12) |
|
|
3 | (1) |
|
Why Pure Functional Programming? |
|
|
4 | (2) |
|
Why Strong Static Typing? |
|
|
6 | (1) |
|
|
7 | (1) |
|
|
8 | (1) |
|
|
9 | (1) |
|
|
10 | (3) |
|
|
13 | (1) |
|
|
14 | (1) |
|
Chapter 2 Declaring the Data Model |
|
|
15 | (48) |
|
Characters, Numbers, and Lists |
|
|
15 | (1) |
|
|
16 | (1) |
|
|
17 | (2) |
|
|
19 | (1) |
|
|
20 | (5) |
|
|
25 | (1) |
|
Creating a Project with Cabal |
|
|
25 | (2) |
|
Creating a Project with Stack |
|
|
27 | (2) |
|
|
29 | (2) |
|
|
31 | (1) |
|
Defining Simple Functions |
|
|
32 | (1) |
|
Creating a Simple Function |
|
|
32 | (1) |
|
Specifying the Function's Type |
|
|
33 | (1) |
|
Developing a Robust Example |
|
|
33 | (3) |
|
Returning More Than One Value |
|
|
36 | (2) |
|
|
38 | (5) |
|
|
43 | (11) |
|
|
54 | (6) |
|
|
60 | (3) |
|
Chapter 3 Increasing Code Reuse |
|
|
63 | (44) |
|
|
64 | (3) |
|
|
67 | (1) |
|
|
68 | (2) |
|
|
70 | (2) |
|
Partial Application of a Function |
|
|
72 | (4) |
|
|
76 | (1) |
|
|
77 | (2) |
|
Smart Constructors and Views |
|
|
79 | (3) |
|
|
82 | (1) |
|
|
82 | (5) |
|
|
87 | (7) |
|
|
94 | (2) |
|
|
96 | (5) |
|
|
101 | (5) |
|
|
106 | (1) |
|
Chapter 4 Using Containers and Type Classes |
|
|
107 | (48) |
|
|
107 | (1) |
|
|
108 | (3) |
|
|
111 | (5) |
|
|
116 | (1) |
|
Containers: Maps, Sets, Trees, Graphs |
|
|
116 | (1) |
|
|
117 | (5) |
|
|
122 | (2) |
|
|
124 | (3) |
|
|
127 | (3) |
|
Ad Hoc Polymorphism: Type Classes |
|
|
130 | (1) |
|
Declaring Classes and Instances |
|
|
130 | (5) |
|
|
135 | (6) |
|
Binary Trees for the Minimum Price |
|
|
141 | (1) |
|
Step 1 Simple Binary Trees |
|
|
141 | (2) |
|
Step 2 Polymorphic Binary Trees |
|
|
143 | (2) |
|
Step 3 Binary Trees with Monoidal Cache |
|
|
145 | (3) |
|
Container-Related Type Classes |
|
|
148 | (1) |
|
|
148 | (3) |
|
|
151 | (2) |
|
|
153 | (2) |
|
Chapter 5 Laziness and Infinite Structures |
|
|
155 | (28) |
|
An Infinite Number of Time Machines |
|
|
156 | (5) |
|
|
161 | (1) |
|
Understanding Evaluation in Haskell |
|
|
161 | (5) |
|
|
166 | (3) |
|
Pattern Matching and Laziness |
|
|
169 | (3) |
|
|
172 | (5) |
|
|
177 | (3) |
|
|
180 | (3) |
|
|
183 | (116) |
|
Chapter 6 Knowing Your Clients Using Monads |
|
|
185 | (44) |
|
|
186 | (1) |
|
|
186 | (7) |
|
|
193 | (9) |
|
|
202 | (1) |
|
Watching Out for Incomplete Data |
|
|
202 | (3) |
|
|
205 | (4) |
|
Dissecting the Combinators |
|
|
209 | (2) |
|
|
211 | (4) |
|
|
215 | (2) |
|
|
217 | (1) |
|
|
217 | (2) |
|
|
219 | (5) |
|
Mutable References with ST |
|
|
224 | (2) |
|
|
226 | (3) |
|
Chapter 7 More Monads: Now for Recommendations |
|
|
229 | (40) |
|
Returning More Than One Value |
|
|
230 | (1) |
|
|
230 | (2) |
|
|
232 | (1) |
|
Failures and Alternatives |
|
|
233 | (4) |
|
Association Rule Learning |
|
|
237 | (1) |
|
Flattening Values into Transactions |
|
|
238 | (3) |
|
|
241 | (5) |
|
|
246 | (1) |
|
|
247 | (1) |
|
|
248 | (3) |
|
|
251 | (1) |
|
Combining Values Under a Monad |
|
|
252 | (3) |
|
|
255 | (4) |
|
|
259 | (1) |
|
|
260 | (4) |
|
|
264 | (3) |
|
|
267 | (2) |
|
Chapter 8 Working in Several Cores |
|
|
269 | (30) |
|
Parallelism, Concurrency, and Distribution |
|
|
269 | (2) |
|
|
271 | (1) |
|
|
272 | (3) |
|
Dataflow Parallelism with IVars |
|
|
275 | (2) |
|
Parallelizing the Apriori Algorithm |
|
|
277 | (3) |
|
Software Transactional Memory |
|
|
280 | (1) |
|
Concurrent Use of Resources |
|
|
280 | (3) |
|
|
283 | (3) |
|
Rolling Back Transactions |
|
|
286 | (2) |
|
|
288 | (1) |
|
|
289 | (2) |
|
Message Queues Using AMQP |
|
|
291 | (2) |
|
|
293 | (4) |
|
|
297 | (2) |
|
Part III Resource Handling |
|
|
299 | (138) |
|
Chapter 9 Dealing with Files: 10 and Conduit |
|
|
301 | (42) |
|
|
301 | (6) |
|
|
307 | (3) |
|
|
310 | (1) |
|
|
310 | (3) |
|
|
313 | (2) |
|
|
315 | (1) |
|
|
316 | (3) |
|
|
319 | (5) |
|
|
324 | (2) |
|
Streaming Data with Conduit |
|
|
326 | (1) |
|
Problems with Lazy Input/Output |
|
|
326 | (2) |
|
|
328 | (4) |
|
Accessing Files via Conduit |
|
|
332 | (2) |
|
Looking Further Than Text Files - |
|
|
334 | (1) |
|
|
335 | (2) |
|
|
337 | (2) |
|
|
339 | (2) |
|
|
341 | (2) |
|
Chapter 10 Building and Parsing Text |
|
|
343 | (36) |
|
The Five Textual Data Types |
|
|
343 | (5) |
|
Building As Fast As the Wind |
|
|
348 | (5) |
|
|
353 | (7) |
|
Introducing New Type Classes |
|
|
360 | (1) |
|
|
361 | (2) |
|
Functors, Applicatives, and Monads |
|
|
363 | (3) |
|
|
366 | (1) |
|
|
367 | (3) |
|
Don't Overengineer: Just Use JSON |
|
|
370 | (8) |
|
|
378 | (1) |
|
Chapter 11 Safe Database Access |
|
|
379 | (30) |
|
Database Access Landscape |
|
|
379 | (1) |
|
Abstracting Over Several DBMSs |
|
|
380 | (1) |
|
Introducing Persistent and Esqueleto |
|
|
381 | (1) |
|
|
382 | (3) |
|
|
385 | (1) |
|
|
386 | (5) |
|
|
391 | (4) |
|
|
395 | (1) |
|
Queries by Identifier or Uniqueness |
|
|
396 | (1) |
|
Selecting Several Entities |
|
|
397 | (3) |
|
SQL Queries with Esqueleto |
|
|
400 | (4) |
|
Insertions, Updates, and Deletions |
|
|
404 | (4) |
|
|
408 | (1) |
|
Chapter 12 Web Applications |
|
|
409 | (28) |
|
|
409 | (1) |
|
|
410 | (2) |
|
Compilation to JavaScript |
|
|
412 | (1) |
|
|
413 | (1) |
|
|
414 | (1) |
|
|
414 | (3) |
|
Showing Products from the Database |
|
|
417 | (5) |
|
Inserting New Products Using Forms |
|
|
422 | (5) |
|
|
427 | (5) |
|
|
432 | (4) |
|
|
436 | (1) |
|
Part IV Domain-Specific Languages |
|
|
437 | (82) |
|
Chapter 13 Strong Types for Describing Offers |
|
|
439 | (44) |
|
Domain-Specific Languages |
|
|
439 | (1) |
|
Embedding Your Language in Haskell |
|
|
440 | (3) |
|
|
443 | (3) |
|
Adding Safety to the Expression Language |
|
|
446 | (4) |
|
|
450 | (1) |
|
Two Styles of Programming |
|
|
451 | (1) |
|
Representing Natural Numbers |
|
|
452 | (2) |
|
|
454 | (1) |
|
Categories of Products with FDs |
|
|
454 | (4) |
|
|
458 | (3) |
|
Enforcing the Presents Rule with FDs |
|
|
461 | (2) |
|
|
463 | (1) |
|
|
464 | (1) |
|
Enforcing the Presents Rule with TFs |
|
|
465 | (1) |
|
Categories of Products with TFs |
|
|
466 | (6) |
|
Data Type Promotion and Singletons |
|
|
472 | (1) |
|
A Further Refinement to the Presents Rule |
|
|
472 | (2) |
|
|
474 | (2) |
|
Enforcing the Duration Rule |
|
|
476 | (6) |
|
|
482 | (1) |
|
Chapter 14 Interpreting Offers with Attributes |
|
|
483 | (36) |
|
Interpretations and Attribute Grammars |
|
|
484 | (1) |
|
|
484 | (1) |
|
Introducing Attribute Grammars |
|
|
484 | (3) |
|
Your First Attribute Grammar |
|
|
487 | (1) |
|
|
488 | (2) |
|
Integrating UUAGC in Your Package |
|
|
490 | (2) |
|
Executing the Attribute Grammar |
|
|
492 | (1) |
|
Expression Interpretation |
|
|
493 | (1) |
|
Using an Attribute Grammar |
|
|
494 | (3) |
|
|
497 | (2) |
|
A Different (Monadic) View |
|
|
499 | (2) |
|
|
501 | (1) |
|
Checking the Presents Rule |
|
|
501 | (2) |
|
Showing an HTML Description |
|
|
503 | (6) |
|
Programming with Data Types |
|
|
509 | (1) |
|
Origami Programming over Any Data Type |
|
|
509 | (3) |
|
Data Type-Generic Programming |
|
|
512 | (4) |
|
|
516 | (3) |
|
Part V Engineering the Store |
|
|
519 | (54) |
|
Chapter 15 Documenting, Testing, and Verifying |
|
|
521 | (24) |
|
Documenting Binary Trees with Haddock |
|
|
522 | (4) |
|
|
526 | (1) |
|
|
527 | (1) |
|
|
528 | (4) |
|
Randomized Testing with QuickCheck |
|
|
532 | (1) |
|
|
533 | (1) |
|
Testing Binary Tree Properties |
|
|
534 | (3) |
|
Formal Verification with LiquidHaskell |
|
|
537 | (4) |
|
Describing Binary Search Trees |
|
|
541 | (2) |
|
|
543 | (2) |
|
Chapter 16 Architecting Your Application |
|
|
545 | (20) |
|
|
545 | (1) |
|
Project and Dependency Management |
|
|
546 | (1) |
|
|
546 | (1) |
|
|
547 | (1) |
|
|
547 | (1) |
|
|
547 | (1) |
|
|
548 | (1) |
|
|
548 | (1) |
|
|
548 | (1) |
|
Design Patterns and Functional Programming |
|
|
549 | (2) |
|
|
551 | (1) |
|
Use Higher-Order Combinators |
|
|
551 | (1) |
|
|
551 | (1) |
|
|
551 | (1) |
|
Enforce Invariants via the Type System |
|
|
552 | (1) |
|
Stay (As) Pure and Polymorphic (As Possible) |
|
|
552 | (1) |
|
|
553 | (1) |
|
|
553 | (7) |
|
Restrictive Monad Classes |
|
|
560 | (1) |
|
|
561 | (3) |
|
|
564 | (1) |
|
Chapter 17 Looking Further |
|
|
565 | (8) |
|
|
565 | (1) |
|
|
566 | (2) |
|
|
568 | (1) |
|
Administration Interface and Tetris |
|
|
569 | (1) |
|
Additional Haskell Resources |
|
|
570 | (1) |
|
Other Functional Languages |
|
|
571 | (2) |
Appendix A Time Travelling with Haskell |
|
573 | (4) |
Index |
|
577 | |