Table Of Contenti
Reader feedback
“Astonishinglyinsightfulexamples. Thisbookisalotlikehavinga
good teacher — it never fails to provide the low-end information
eventhoughIhavealreadymovedon. Sojustlikeagoodteacherisn’t
presumptuousinwhatI’msupposedtoknow(whichmightforceme
totryandsavefaceincaseIdonot,yet),informationconveniently
resurfaces.” –DavidDeutsch
“When@haskellbookisdone,itwillbeanunexpectedmilestone
for#haskell. TherewillforeverbeHaskellbefore,andHaskellafter.”
–JasonKuhrt
“IfeelsaferecommendingHaskelltobeginnersnowthat@haskell-
bookisavailable,whichisverybeginnerfriendly”–GabrielGonzalez
“”Structure and Interpretation of Computer Programs” has its
credit, but @haskellbook is now my #1 recommendation for FP
beginners.” –IrioMusskopf
“The book is long, but not slow — a large fraction of it is made
upofexamplesandexercises. Youcantellit’swrittenbysomeone
who’staughtHaskelltoprogrammersbefore.” –ChristopherJones
“IalreadyhavealotofexperiencewithHaskell,butI’veneverfelt
confidentinitthewaythisbookhasmademefeel.” –AlainO’Dea
“Realdealwith@haskellbookisthatyoudon’tjustlearnHaskell;
yougetahandsonexperienceastowhyfunctionalprogramming
works.” –GeorgeMakrydakis
“One of my goals this year is to evangelize @haskellbook and
@HaskellForMac. I think these tools will make anyone who uses
thembetter. IwanttogetcomfortablewithitsothatIcanshifthow
IthinkaboutSwift.” –JanieClayton
Contents
Readerfeedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . i
Contents ii
Authors’preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiv
Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
WhyThisBook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Afewwordstonewprogrammers . . . . . . . . . . . . . . . . . xxiii
Haskevangelism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv
What’sinthisbook? . . . . . . . . . . . . . . . . . . . . . . . . . . xxvi
Bestpracticesforexamplesandexercises . . . . . . . . . . . . xxix
1 AllYouNeedisLambda 1
1.1 AllYouNeedisLambda . . . . . . . . . . . . . . . . . . . . 2
1.2 Whatisfunctionalprogramming? . . . . . . . . . . . . . 2
1.3 Whatisafunction? . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Thestructureoflambdaterms . . . . . . . . . . . . . . . 5
1.5 Betareduction . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.6 Multiplearguments . . . . . . . . . . . . . . . . . . . . . . 10
1.7 Evaluationissimplification. . . . . . . . . . . . . . . . . . 14
1.8 Combinators . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.9 Divergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.11 ChapterExercises . . . . . . . . . . . . . . . . . . . . . . . . 17
1.12 Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.13 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
1.14 Follow-upresources . . . . . . . . . . . . . . . . . . . . . . 23
2 Hello,Haskell! 24
2.1 Hello,Haskell . . . . . . . . . . . . . . . . . . . . . . . . . . 25
ii
CONTENTS iii
2.2 InteractingwithHaskellcode . . . . . . . . . . . . . . . . 25
2.3 Understandingexpressions. . . . . . . . . . . . . . . . . . 28
2.4 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.5 Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.6 Infixoperators . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.7 Declaringvalues . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.8 ArithmeticfunctionsinHaskell . . . . . . . . . . . . . . . 45
2.9 Parenthesization . . . . . . . . . . . . . . . . . . . . . . . . 52
2.10 Letandwhere . . . . . . . . . . . . . . . . . . . . . . . . . . 57
2.11 ChapterExercises . . . . . . . . . . . . . . . . . . . . . . . . 60
2.12 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
2.13 Follow-upresources . . . . . . . . . . . . . . . . . . . . . . 64
3 Strings 65
3.1 Printingstrings . . . . . . . . . . . . . . . . . . . . . . . . . 66
3.2 Afirstlookattypes . . . . . . . . . . . . . . . . . . . . . . . 66
3.3 Printingsimplestrings . . . . . . . . . . . . . . . . . . . . 67
3.4 Top-levelversuslocaldefinitions . . . . . . . . . . . . . . 72
3.5 Typesofconcatenationfunctions . . . . . . . . . . . . . 74
3.6 Concatenationandscoping . . . . . . . . . . . . . . . . . 76
3.7 Morelistfunctions . . . . . . . . . . . . . . . . . . . . . . . 79
3.8 ChapterExercises . . . . . . . . . . . . . . . . . . . . . . . . 81
3.9 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4 Basicdatatypes 86
4.1 BasicDatatypes . . . . . . . . . . . . . . . . . . . . . . . . . 87
4.2 Whataretypes? . . . . . . . . . . . . . . . . . . . . . . . . . 87
4.3 Anatomyofadatadeclaration . . . . . . . . . . . . . . . 87
4.4 Numerictypes . . . . . . . . . . . . . . . . . . . . . . . . . . 90
4.5 Comparingvalues . . . . . . . . . . . . . . . . . . . . . . . 96
4.6 GoonandBoolme . . . . . . . . . . . . . . . . . . . . . . . 99
4.7 Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
4.8 Lists. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
4.9 ChapterExercises . . . . . . . . . . . . . . . . . . . . . . . . 109
4.10 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
4.11 Namesandvariables . . . . . . . . . . . . . . . . . . . . . . 115
5 Types 117
5.1 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
CONTENTS iv
5.2 Whataretypesfor? . . . . . . . . . . . . . . . . . . . . . . . 118
5.3 Howtoreadtypesignatures . . . . . . . . . . . . . . . . . 120
5.4 Currying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
5.5 Polymorphism. . . . . . . . . . . . . . . . . . . . . . . . . . 137
5.6 Typeinference . . . . . . . . . . . . . . . . . . . . . . . . . 142
5.7 Assertingtypesfordeclarations . . . . . . . . . . . . . . . 146
5.8 ChapterExercises . . . . . . . . . . . . . . . . . . . . . . . . 147
5.9 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
5.10 Follow-upresources . . . . . . . . . . . . . . . . . . . . . . 161
6 Typeclasses 162
6.1 Typeclasses . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
6.2 Whataretypeclasses? . . . . . . . . . . . . . . . . . . . . . 163
6.3 BacktoBool . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
6.4 Eq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
6.5 Writingtypeclassinstances . . . . . . . . . . . . . . . . . . 169
6.6 Num . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
6.7 Type-defaultingtypeclasses . . . . . . . . . . . . . . . . . 182
6.8 Ord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
6.9 Enum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
6.10 Show . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
6.11 Read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
6.12 Instancesaredispatchedbytype . . . . . . . . . . . . . . 199
6.13 Gimmemoreoperations . . . . . . . . . . . . . . . . . . . 203
6.14 ChapterExercises . . . . . . . . . . . . . . . . . . . . . . . . 206
6.15 ChapterDefinitions . . . . . . . . . . . . . . . . . . . . . . 211
6.16 Typeclassinheritance,partial . . . . . . . . . . . . . . . . 214
6.17 Follow-upresources . . . . . . . . . . . . . . . . . . . . . . 214
7 Morefunctionalpatterns 215
7.1 Makeitfunc-y . . . . . . . . . . . . . . . . . . . . . . . . . . 216
7.2 Argumentsandparameters . . . . . . . . . . . . . . . . . 216
7.3 Anonymousfunctions . . . . . . . . . . . . . . . . . . . . . 223
7.4 Patternmatching . . . . . . . . . . . . . . . . . . . . . . . . 226
7.5 Caseexpressions . . . . . . . . . . . . . . . . . . . . . . . . 236
7.6 Higher-orderfunctions . . . . . . . . . . . . . . . . . . . . 239
7.7 Guards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
7.8 Functioncomposition . . . . . . . . . . . . . . . . . . . . . 253
7.9 Pointfreestyle . . . . . . . . . . . . . . . . . . . . . . . . . . 257
CONTENTS v
7.10 Demonstratingcomposition . . . . . . . . . . . . . . . . . 259
7.11 ChapterExercises . . . . . . . . . . . . . . . . . . . . . . . . 262
7.12 ChapterDefinitions . . . . . . . . . . . . . . . . . . . . . . 266
7.13 Follow-upresources . . . . . . . . . . . . . . . . . . . . . . 274
8 Recursion 275
8.1 Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
8.2 Factorial! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
8.3 Bottom. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
8.4 Fibonaccinumbers . . . . . . . . . . . . . . . . . . . . . . . 286
8.5 Integraldivisionfromscratch . . . . . . . . . . . . . . . . 289
8.6 ChapterExercises . . . . . . . . . . . . . . . . . . . . . . . . 294
8.7 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
9 Lists 300
9.1 Lists. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
9.2 Thelistdatatype . . . . . . . . . . . . . . . . . . . . . . . . 301
9.3 Patternmatchingonlists . . . . . . . . . . . . . . . . . . . 302
9.4 List’ssyntacticsugar . . . . . . . . . . . . . . . . . . . . . . 304
9.5 Usingrangestoconstructlists . . . . . . . . . . . . . . . . 305
9.6 Extractingportionsoflists . . . . . . . . . . . . . . . . . . 308
9.7 Listcomprehensions . . . . . . . . . . . . . . . . . . . . . . 312
9.8 Spinesandnonstrictevaluation . . . . . . . . . . . . . . . 318
9.9 Transforminglistsofvalues . . . . . . . . . . . . . . . . . 327
9.10 Filteringlistsofvalues . . . . . . . . . . . . . . . . . . . . . 334
9.11 Zippinglists . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
9.12 ChapterExercises . . . . . . . . . . . . . . . . . . . . . . . . 339
9.13 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
9.14 Follow-upresources . . . . . . . . . . . . . . . . . . . . . . 347
10 Foldinglists 348
10.1 Folds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
10.2 Bringingyouintothefold . . . . . . . . . . . . . . . . . . 349
10.3 Recursivepatterns . . . . . . . . . . . . . . . . . . . . . . . 351
10.4 Foldright . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
10.5 Foldleft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
10.6 Howtowritefoldfunctions . . . . . . . . . . . . . . . . . 368
10.7 Foldingandevaluation . . . . . . . . . . . . . . . . . . . . 373
10.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
CONTENTS vi
10.9 Scans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
10.10 ChapterExercises . . . . . . . . . . . . . . . . . . . . . . . . 379
10.11 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
10.12 Follow-upresources . . . . . . . . . . . . . . . . . . . . . . 386
11 Algebraicdatatypes 387
11.1 Algebraicdatatypes. . . . . . . . . . . . . . . . . . . . . . . 388
11.2 Datadeclarationsreview . . . . . . . . . . . . . . . . . . . 388
11.3 Dataandtypeconstructors . . . . . . . . . . . . . . . . . . 390
11.4 Typeconstructorsandkinds . . . . . . . . . . . . . . . . . 392
11.5 Dataconstructorsandvalues . . . . . . . . . . . . . . . . 393
11.6 What’satypeandwhat’sdata? . . . . . . . . . . . . . . . 397
11.7 Dataconstructorarities . . . . . . . . . . . . . . . . . . . . 400
11.8 Whatmakesthesedatatypesalgebraic? . . . . . . . . . . 403
11.9 newtype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
11.10 Sumtypes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
11.11 Producttypes . . . . . . . . . . . . . . . . . . . . . . . . . . 414
11.12 Normalform . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
11.13 Constructinganddeconstructingvalues . . . . . . . . . 421
11.14 Functiontypeisexponential. . . . . . . . . . . . . . . . . 435
11.15 Higher-kindeddatatypes . . . . . . . . . . . . . . . . . . . 441
11.16 Listsarepolymorphic . . . . . . . . . . . . . . . . . . . . . 443
11.17 BinaryTree . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
11.18 ChapterExercises . . . . . . . . . . . . . . . . . . . . . . . . 452
11.19 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
12 Signalingadversity 461
12.1 Signalingadversity . . . . . . . . . . . . . . . . . . . . . . . 462
12.2 HowIlearnedtostopworryingandloveNothing . . . 462
12.3 Bleatingeither . . . . . . . . . . . . . . . . . . . . . . . . . . 465
12.4 Kinds,athousandstarsinyourtypes . . . . . . . . . . . 471
12.5 ChapterExercises . . . . . . . . . . . . . . . . . . . . . . . . 480
12.6 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
13 Buildingprojects 492
13.1 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
13.2 MakingpackageswithStack . . . . . . . . . . . . . . . . . 494
13.3 Workingwithabasicproject . . . . . . . . . . . . . . . . . 495
13.4 Makingourprojectalibrary . . . . . . . . . . . . . . . . . 498
CONTENTS vii
13.5 Moduleexports . . . . . . . . . . . . . . . . . . . . . . . . . 500
13.6 Moreonimportingmodules. . . . . . . . . . . . . . . . . 502
13.7 Makingourprograminteractive . . . . . . . . . . . . . . 507
13.8 dosyntaxandIO . . . . . . . . . . . . . . . . . . . . . . . . 510
13.9 Hangmangame . . . . . . . . . . . . . . . . . . . . . . . . . 514
13.10 StepOne: Importingmodules . . . . . . . . . . . . . . . 516
13.11 StepTwo: Generatingawordlist . . . . . . . . . . . . . . 519
13.12 StepThree: Makingapuzzle . . . . . . . . . . . . . . . . 522
13.13 Addinganewtype. . . . . . . . . . . . . . . . . . . . . . . . 530
13.14 Chapterexercises . . . . . . . . . . . . . . . . . . . . . . . . 531
13.15 Follow-upresources . . . . . . . . . . . . . . . . . . . . . . 534
14 Testing 535
14.1 Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536
14.2 Aquicktouroftestingfortheuninitiated . . . . . . . . 536
14.3 Conventionaltesting . . . . . . . . . . . . . . . . . . . . . . 538
14.4 EnterQuickCheck . . . . . . . . . . . . . . . . . . . . . . . 545
14.5 Morsecode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554
14.6 Arbitraryinstances . . . . . . . . . . . . . . . . . . . . . . . 565
14.7 ChapterExercises . . . . . . . . . . . . . . . . . . . . . . . . 573
14.8 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
14.9 Follow-upresources . . . . . . . . . . . . . . . . . . . . . . 580
15 Monoid,Semigroup 581
15.1 Monoidsandsemigroups . . . . . . . . . . . . . . . . . . . 582
15.2 Whatwetalkaboutwhenwetalkaboutalgebras . . . . 582
15.3 Monoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583
15.4 HowMonoidisdefinedinHaskell . . . . . . . . . . . . . 584
15.5 ExamplesofusingMonoid . . . . . . . . . . . . . . . . . . 585
15.6 WhyIntegerdoesn’thaveaMonoid . . . . . . . . . . . . 586
15.7 Whybother? . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
15.8 Laws . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
15.9 Differentinstance,samerepresentation . . . . . . . . . 594
15.10 Reusingalgebrasbyaskingforalgebras. . . . . . . . . . 596
15.11 Madness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
15.12 BetterlivingthroughQuickCheck . . . . . . . . . . . . . 605
15.13 Semigroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612
15.14 Strengthcanbeweakness . . . . . . . . . . . . . . . . . . . 615
15.15 Chapterexercises . . . . . . . . . . . . . . . . . . . . . . . . 617
CONTENTS viii
15.16 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624
15.17 Follow-upresources . . . . . . . . . . . . . . . . . . . . . . 625
16 Functor 626
16.1 Functor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627
16.2 What’safunctor? . . . . . . . . . . . . . . . . . . . . . . . . 628
16.3 There’sawholelotoffmapgoin’round . . . . . . . . . . 629
16.4 Let’stalkabout𝑓,baby . . . . . . . . . . . . . . . . . . . . 631
16.5 FunctorLaws . . . . . . . . . . . . . . . . . . . . . . . . . . . 640
16.6 TheGood,theBad,andtheUgly . . . . . . . . . . . . . . 641
16.7 Commonlyusedfunctors . . . . . . . . . . . . . . . . . . 645
16.8 Transformingtheunappliedtypeargument . . . . . . 657
16.9 QuickCheckingFunctorinstances . . . . . . . . . . . . . 660
16.10 Exercises: InstancesofFunc . . . . . . . . . . . . . . . . . 663
16.11 Ignoringpossibilities . . . . . . . . . . . . . . . . . . . . . . 663
16.12 Asomewhatsurprisingfunctor . . . . . . . . . . . . . . . 669
16.13 Morestructure,morefunctors . . . . . . . . . . . . . . . 672
16.14 IOFunctor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673
16.15 Whatifwewanttodosomethingdifferent? . . . . . . . 675
16.16 Functorsareuniquetoadatatype . . . . . . . . . . . . . 678
16.17 Chapterexercises . . . . . . . . . . . . . . . . . . . . . . . . 679
16.18 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683
16.19 Follow-upresources . . . . . . . . . . . . . . . . . . . . . . 685
17 Applicative 686
17.1 Applicative . . . . . . . . . . . . . . . . . . . . . . . . . . . . 687
17.2 DefiningApplicative . . . . . . . . . . . . . . . . . . . . . . 687
17.3 Functorvs. Applicative . . . . . . . . . . . . . . . . . . . . 689
17.4 Applicativefunctorsaremonoidalfunctors . . . . . . . 691
17.5 Applicativeinuse . . . . . . . . . . . . . . . . . . . . . . . . 696
17.6 Applicativelaws . . . . . . . . . . . . . . . . . . . . . . . . . 721
17.7 Youknewthiswascoming . . . . . . . . . . . . . . . . . . 727
17.8 ZipListMonoid . . . . . . . . . . . . . . . . . . . . . . . . . 730
17.9 ChapterExercises . . . . . . . . . . . . . . . . . . . . . . . . 741
17.10 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742
17.11 Follow-upresources . . . . . . . . . . . . . . . . . . . . . . 743
18 Monad 744
18.1 Monad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 745
CONTENTS ix
18.2 Sorry—amonadisnotaburrito . . . . . . . . . . . . . 745
18.3 Dosyntaxandmonads . . . . . . . . . . . . . . . . . . . . 753
18.4 ExamplesofMonaduse . . . . . . . . . . . . . . . . . . . . . 759
18.5 Monadlaws . . . . . . . . . . . . . . . . . . . . . . . . . . . . 776
18.6 Applicationandcomposition . . . . . . . . . . . . . . . . 783
18.7 ChapterExercises . . . . . . . . . . . . . . . . . . . . . . . . 788
18.8 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 789
18.9 Follow-upresources . . . . . . . . . . . . . . . . . . . . . . 791
19 Applyingstructure 792
19.1 Appliedstructure . . . . . . . . . . . . . . . . . . . . . . . . 793
19.2 Monoid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 793
19.3 Functor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 798
19.4 Applicative . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801
19.5 Monad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 806
19.6 Anend-to-endexample: URLshortener . . . . . . . . . 807
19.7 That’sawrap! . . . . . . . . . . . . . . . . . . . . . . . . . . 820
19.8 Follow-upresources . . . . . . . . . . . . . . . . . . . . . . 821
20Foldable 822
20.1 Foldable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 823
20.2 TheFoldableclass . . . . . . . . . . . . . . . . . . . . . . . . 823
20.3 Revengeofthemonoids . . . . . . . . . . . . . . . . . . . 824
20.4 DemonstratingFoldableinstances . . . . . . . . . . . . . 828
20.5 Somebasicderivedoperations . . . . . . . . . . . . . . . 831
20.6 ChapterExercises . . . . . . . . . . . . . . . . . . . . . . . . 836
20.7 Follow-upresources . . . . . . . . . . . . . . . . . . . . . . 837
21 Traversable 838
21.1 Traversable . . . . . . . . . . . . . . . . . . . . . . . . . . . . 839
21.2 TheTraversabletypeclassdefinition . . . . . . . . . . . . 839
21.3 sequenceA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 840
21.4 traverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 842
21.5 So,what’sTraversablefor? . . . . . . . . . . . . . . . . . . . 844
21.6 Morsecoderevisited . . . . . . . . . . . . . . . . . . . . . . 845
21.7 Axingtediouscode . . . . . . . . . . . . . . . . . . . . . . . 848
21.8 Doallthethings . . . . . . . . . . . . . . . . . . . . . . . . . 850
21.9 Traversableinstances . . . . . . . . . . . . . . . . . . . . . 852
21.10 TraversableLaws . . . . . . . . . . . . . . . . . . . . . . . . . 854