Functional Programming Using F#

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

This comprehensive introduction to the principles of functional programming using F# shows how to apply basic theoretical concepts to produce succinct and elegant programs. It demonstrates the role of functional programming in a wide spectrum of applications including databases and systems. Coverage also includes advanced features in the .NET library, the imperative features of F# and topics such as text processing, sequences, computation expressions and asynchronous computation. With a broad spectrum of examples and exercises, the book is perfect for courses in functional programming and for self-study. Enhancing its use as a text is an accompanying website with downloadable programs, lecture slides, a mini-projects and links to further F# sources.

Author(s): Michael R. Hansen, Hans Rischel
Publisher: Cambridge University Press
Year: 2013

Language: English
Pages: 371
Tags: Библиотека;Компьютерная литература;F#;

CONTENTS......Page 7
Preface......Page 11
1.1 Values, types, identifiers and declarations......Page 15
1.2 Simple function declarations......Page 16
1.3 Anonymous functions. Function expressions......Page 18
1.4 Recursion......Page 20
1.5 Pairs......Page 25
1.6 Types and type checking......Page 27
1.7 Bindings and environments......Page 28
1.8 Euclid’s algorithm......Page 29
1.9 Evaluations with environments......Page 31
Summary......Page 33
Exercises......Page 34
2.1 Numbers. Truth values. The unit type......Page 35
2.2 Operator precedence and association......Page 37
2.3 Characters and strings......Page 38
2.4 If-then-else expressions......Page 42
2.5 Overloaded functions and operators......Page 43
2.7 Functions are first-class citizens......Page 45
2.8 Closures......Page 48
2.9 Declaring prefix and infix operators......Page 49
2.10 Equality and ordering......Page 50
2.12 Summary of the basic types......Page 52
Exercises......Page 53
3.1 Tuples......Page 57
3.3 Example: Geometric vectors......Page 62
3.4 Records......Page 64
3.5 Example: Quadratic equations......Page 66
3.6 Locally declared identifiers......Page 68
3.7 Example: Rational numbers. Invariants......Page 70
3.8 Tagged values. Constructors......Page 72
3.9 Enumeration types......Page 76
3.10 Exceptions......Page 77
3.11 Partial functions. The option type......Page 78
Summary......Page 79
Exercises......Page 80
4.1 The concept of a list......Page 81
4.2 Construction and decomposition of lists......Page 85
4.3 Typical recursions over lists......Page 88
4.4 Polymorphism......Page 92
4.5 The value restrictions on polymorphic expressions......Page 95
4.6 Examples. A model-based approach......Page 96
Summary......Page 102
Exercises......Page 103
5.1 Lists......Page 107
5.2 Finite sets......Page 118
5.3 Maps......Page 127
Exercises......Page 133
6.1 Chinese boxes......Page 135
6.2 Symbolic differentiation......Page 141
6.3 Binary trees. Parameterized types......Page 145
6.4 Traversal of binary trees. Search trees......Page 147
6.5 Expression trees......Page 151
6.6 Trees with a variable number of sub-trees. Mutual recursion......Page 152
6.7 Electrical circuits......Page 156
Summary......Page 158
Exercises......Page 159
7.1 Abstractions......Page 163
7.2 Signature and implementation......Page 164
7.3 Type augmentation. Operators in modules......Page 167
7.4 Type extension......Page 169
7.5 Classes and objects......Page 170
7.6 Parameterized modules. Type variables in signatures......Page 171
7.7 Customizing equality, hashing and the string function......Page 173
7.8 Customizing ordering and indexing......Page 175
7.9 Example: Piecewise linear plane curves......Page 176
Exercises......Page 184
8.1 Locations......Page 189
8.2 Operators on locations......Page 190
8.4 Sequential composition......Page 193
8.5 Mutable record fields......Page 194
8.6 References......Page 196
8.7 While loops......Page 197
8.8 Imperative functions on lists and other collections......Page 198
8.9 Imperative tree traversal......Page 199
8.10 Arrays......Page 200
8.11 Imperative set and map......Page 202
8.12 Functions on collections. Enumerator functions......Page 204
8.13 Imperative queue......Page 208
Summary......Page 209
Exercises......Page 210
9.1 Resource measures......Page 211
9.2 Memory management......Page 212
9.3 Two problems......Page 218
9.4 Solutions using accumulating parameters......Page 220
9.5 Iterative function declarations......Page 223
9.6 Tail recursion obtained using continuations......Page 226
Exercises......Page 230
10.1 Keyword index example: Problem statement......Page 233
10.2 Capturing data using regular expressions......Page 235
10.3 Text I/O......Page 243
10.4 File handling. Save and restore values in files......Page 244
10.6 Culture-dependent information. String orderings......Page 246
10.7 Conversion to textual form. Date and time......Page 249
10.8 Keyword index example: The IndexGen program......Page 252
10.9 Keyword index example: Analysis of a web-source......Page 256
10.10 Keyword index example: Putting it all together......Page 259
Summary......Page 262
Exercises......Page 263
11.1 The sequence concept in F#......Page 265
11.2 Some operations on sequences......Page 268
11.3 Delays, recursion and side-effects......Page 270
11.4 Example: Sieve of Eratosthenes......Page 272
11.5 Limits of sequences: Newton-Raphson approximations......Page 274
11.6 Sequence expressions......Page 276
11.7 Specializations of sequences......Page 280
11.8 Type providers and databases......Page 281
Exercises......Page 291
12 Computation expressions......Page 293
12.1 The agenda when defining your own computations......Page 294
12.2 Introducing computation expressions using sequence expressions......Page 295
12.3 The basic functions: For and Yield......Page 296
12.4 The technical setting when defining your own computations......Page 298
12.5 Example: Expression evaluation with error handling......Page 299
12.6 The basic functions: Bind, Return, ReturnFrom and Zero......Page 300
12.7 Controlling the computations: Delay and Start......Page 302
12.8 The basic function: Delay......Page 304
12.9 The fundamental properties of For and Yield, Bind and Return......Page 305
12.10 Monadic parsers......Page 307
Exercises......Page 323
13.1 Multi-core processors, cache memories and main memory......Page 325
13.2 Processes, threads and tasks......Page 326
13.3 Challenges and pitfalls in concurrency......Page 328
13.4 Asynchronous computations......Page 330
13.5 Reactive programs......Page 335
13.6 Parallel computations......Page 342
Summary......Page 349
Exercises......Page 350
A.1 Web source files......Page 353
A.2 The IndexGen program......Page 356
A.3 The NextLevelRefs program......Page 358
Appendix B The TextProcessing library......Page 360
Appendix C The dialogue program from Chapter 13......Page 364
References......Page 367
Index......Page 369