Christopher Allen, Julie Moronuki - Haskell Programming from first principles (2016) - libgen.lc

Telechargé par ninolux
Contents
Contents 2
License ................................... 12
Authorspreface ............................. 13
Acknowledgements ........................... 18
Introduction................................ 20
A few words about the examples and exercises . . . . . . . . . . 26
1 All You Need is Lambda 29
1.1 All You Need is Lambda . . . . . . . . . . . . . . . . . . . 30
1.2 What is functional programming? . . . . . . . . . . . . 30
1.3 What is a function? . . . . . . . . . . . . . . . . . . . . . . 31
1.4 The structure of lambda terms . . . . . . . . . . . . . . . 32
1.5 Betareduction ......................... 34
1.6 Multiple arguments . . . . . . . . . . . . . . . . . . . . . . 37
1.7 Evaluation is simplification . . . . . . . . . . . . . . . . . 40
1.8 Combinators .......................... 41
1.9 Divergence ........................... 41
1.10 Summary ............................ 42
1.11 Exercises............................. 43
1.12 Answers.............................. 45
1.13 Denitions............................ 48
1.14 Follow-up resources . . . . . . . . . . . . . . . . . . . . . . 48
2 Hello, Haskell! 50
2.1 Hello,Haskell.......................... 51
2.2 Interacting with Haskell code . . . . . . . . . . . . . . . . 51
2.3 Understanding expressions . . . . . . . . . . . . . . . . . 53
2.4 Functions ............................ 55
2.5 Inxoperators ......................... 60
2.6 Declaring values . . . . . . . . . . . . . . . . . . . . . . . . 63
2.7 Arithmetic functions in Haskell . . . . . . . . . . . . . . 69
2.8 Negative numbers . . . . . . . . . . . . . . . . . . . . . . . 73
2
CONTENTS 3
2.9 Parenthesizing infix functions . . . . . . . . . . . . . . . 74
2.10 Laws for quotients and remainders . . . . . . . . . . . . 76
2.11 Evaluation............................ 77
2.12 Letandwhere.......................... 77
2.13 Chapter Exercises . . . . . . . . . . . . . . . . . . . . . . . 82
2.14 Denitions............................ 88
2.15 Follow-up resources . . . . . . . . . . . . . . . . . . . . . . 89
3 Strings 90
3.1 Printingstrings......................... 91
3.2 A first look at types . . . . . . . . . . . . . . . . . . . . . . 91
3.3 Printing simple strings . . . . . . . . . . . . . . . . . . . . 92
3.4 Types of concatenation functions . . . . . . . . . . . . . 97
3.5 Concatenation and scoping . . . . . . . . . . . . . . . . . 99
3.6 More list functions . . . . . . . . . . . . . . . . . . . . . . 101
3.7 Chapter Exercises . . . . . . . . . . . . . . . . . . . . . . . 103
3.8 Denitions............................107
4 Basic datatypes 108
4.1 BasicDatatypes.........................109
4.2 Anatomy of a data declaration . . . . . . . . . . . . . . . 109
4.3 Numerictypes ......................... 111
4.4 Comparing values . . . . . . . . . . . . . . . . . . . . . . . 116
4.5 Tuples...............................123
4.6 Lists ................................125
4.7 Chapter Exercises . . . . . . . . . . . . . . . . . . . . . . . 126
4.8 Denitions............................130
4.9 Answers..............................131
5 Types 135
5.1 Types ...............................136
5.2 Whataretypes?.........................136
5.3 Querying and Reading Types . . . . . . . . . . . . . . . 139
5.4 Typeclass constrained type variables . . . . . . . . . . . 141
5.5 Currying.............................144
5.6 Polymorphism .........................153
5.7 Typeinference.........................158
5.8 Asserting types for declarations . . . . . . . . . . . . . . 161
5.9 Chapter Exercises . . . . . . . . . . . . . . . . . . . . . . . 163
5.10 Denitions............................171
5.11 Follow-up resources . . . . . . . . . . . . . . . . . . . . . . 173
6 Typeclasses 174
6.1 Typeclasses ...........................175
CONTENTS 4
6.2 What are typeclasses? . . . . . . . . . . . . . . . . . . . . . 175
6.3 BacktoBool...........................176
6.4 Eq .................................177
6.5 Num................................180
6.6 Type-defaulting typeclasses . . . . . . . . . . . . . . . . . 182
6.7 Ord ................................186
6.8 Enum...............................189
6.9 Show ...............................190
6.10 Read................................194
6.11 Instances are dispatched by type . . . . . . . . . . . . . 195
6.12 Writing typeclass instances . . . . . . . . . . . . . . . . . 198
6.13 Gimme more operations . . . . . . . . . . . . . . . . . . 208
6.14 Chapter Exercises . . . . . . . . . . . . . . . . . . . . . . . 211
6.15 Chapter Definitions . . . . . . . . . . . . . . . . . . . . . . 217
6.16 Typeclass inheritance, partial . . . . . . . . . . . . . . . . 219
6.17 Follow-up resources . . . . . . . . . . . . . . . . . . . . . . 219
7 More functional patterns 220
7.1 Makeitfunc-y .........................221
7.2 Arguments and parameters . . . . . . . . . . . . . . . . . 221
7.3 Anonymous functions . . . . . . . . . . . . . . . . . . . . 226
7.4 Pattern matching . . . . . . . . . . . . . . . . . . . . . . . . 229
7.5 Case expressions . . . . . . . . . . . . . . . . . . . . . . . . 237
7.6 Higher-order functions . . . . . . . . . . . . . . . . . . . 239
7.7 Guards ..............................246
7.8 Function composition . . . . . . . . . . . . . . . . . . . . 251
7.9 Pointfreestyle .........................254
7.10 Demonstrating composition . . . . . . . . . . . . . . . . 256
7.11 Chapter Exercises . . . . . . . . . . . . . . . . . . . . . . . 259
7.12 Chapter Definitions . . . . . . . . . . . . . . . . . . . . . . 263
7.13 Follow-up resources . . . . . . . . . . . . . . . . . . . . . . 268
8 Recursion 269
8.1 Recursion ............................270
8.2 Factorial .............................271
8.3 Bottom..............................276
8.4 Fibonacci numbers . . . . . . . . . . . . . . . . . . . . . . 279
8.5 Integral division from scratch . . . . . . . . . . . . . . . 282
8.6 Chapter Exercises . . . . . . . . . . . . . . . . . . . . . . . 286
8.7 Denitions............................291
9 Lists 292
9.1 Lists ................................293
9.2 The list datatype . . . . . . . . . . . . . . . . . . . . . . . . 293
CONTENTS 5
9.3 Pattern matching on lists . . . . . . . . . . . . . . . . . . 294
9.4 List’s syntactic sugar . . . . . . . . . . . . . . . . . . . . . 296
9.5 Using ranges to construct lists . . . . . . . . . . . . . . . 297
9.6 Extracting portions of lists . . . . . . . . . . . . . . . . . 299
9.7 List comprehensions . . . . . . . . . . . . . . . . . . . . . 303
9.8 Spines and non-strict evaluation . . . . . . . . . . . . . 307
9.9 Transforming lists of values . . . . . . . . . . . . . . . . . 315
9.10 Filtering lists of values . . . . . . . . . . . . . . . . . . . . 321
9.11 Zippinglists...........................323
9.12 Chapter Exercises . . . . . . . . . . . . . . . . . . . . . . . 325
9.13 Denitions............................331
9.14 Answers..............................332
9.15 Follow-up resources . . . . . . . . . . . . . . . . . . . . . . 335
10 Folding lists 336
10.1 Folds................................337
10.2 Bringing you into the fold . . . . . . . . . . . . . . . . . . 337
10.3 Recursive patterns . . . . . . . . . . . . . . . . . . . . . . . 338
10.4 Foldright.............................339
10.5 Foldle..............................345
10.6 How to write fold functions . . . . . . . . . . . . . . . . . 353
10.7 Folding and evaluation . . . . . . . . . . . . . . . . . . . . 357
10.8 Summary ............................358
10.9 Scans ...............................359
10.10 Chapter Exercises . . . . . . . . . . . . . . . . . . . . . . . 362
10.11 Denitions............................367
10.12 Answers..............................368
10.13 Follow-up resources . . . . . . . . . . . . . . . . . . . . . . 374
11 Algebraic datatypes 375
11.1 Algebraic datatypes . . . . . . . . . . . . . . . . . . . . . . 376
11.2 Data declarations review . . . . . . . . . . . . . . . . . . . 376
11.3 Data and type constructors . . . . . . . . . . . . . . . . . 378
11.4 Data constructors and values . . . . . . . . . . . . . . . . 380
11.5 What’s a type and what’s data? . . . . . . . . . . . . . . . 384
11.6 Data constructor arities . . . . . . . . . . . . . . . . . . . 387
11.7 What makes these datatypes algebraic? . . . . . . . . . 389
11.8 Sumtypes ............................397
11.9 Producttypes..........................399
11.10 Normalform ..........................403
11.11 Constructing and deconstructing values . . . . . . . . . 406
11.12 Function type is exponential . . . . . . . . . . . . . . . . 419
11.13 Higher-kinded datatypes . . . . . . . . . . . . . . . . . . 423
1 / 1076 100%

Christopher Allen, Julie Moronuki - Haskell Programming from first principles (2016) - libgen.lc

Telechargé par ninolux
La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !