Book contents
- Frontmatter
- Contents
- Preface
- 1 Getting started
- 2 Values, operators, expressions and functions
- 3 Tuples, records and tagged values
- 4 Lists
- 5 Collections: Lists, maps and sets
- 6 Finite trees
- 7 Modules
- 8 Imperative features
- 9 Efficiency
- 10 Text processing programs
- 11 Sequences
- 12 Computation expressions
- 13 Asynchronous and parallel computations
- Appendix A Programs from the keyword example
- Appendix B The TextProcessing library
- Appendix C The dialogue program from Chapter 13
- References
- Index
7 - Modules
Published online by Cambridge University Press: 05 May 2013
- Frontmatter
- Contents
- Preface
- 1 Getting started
- 2 Values, operators, expressions and functions
- 3 Tuples, records and tagged values
- 4 Lists
- 5 Collections: Lists, maps and sets
- 6 Finite trees
- 7 Modules
- 8 Imperative features
- 9 Efficiency
- 10 Text processing programs
- 11 Sequences
- 12 Computation expressions
- 13 Asynchronous and parallel computations
- Appendix A Programs from the keyword example
- Appendix B The TextProcessing library
- Appendix C The dialogue program from Chapter 13
- References
- Index
Summary
Throughout the book we have used programs from the F# core library and from the .NET library, and we have seen that programs from these libraries are reused in many different applications. In this chapter we show how the user can make own libraries by means of modules consisting of signature and implementation files. The implementation file contains the declarations of the entities in the library while the signature file specifies the user's interface to the library.
Overloaded operators are defined by adding augmentations to type definitions. Type augmentations can also be used to customize the equality and comparison operators and the string conversion function. Libraries with polymorphic types are obtained by using signatures containing type variables.
These features of the module system are illustrated by small examples: plane geometric vectors and queues of values with arbitrary type. The last part of the chapter illustrates the module system by a larger example of piecewise linear plane curves. The curve library is used to describe the recursively defined family of Hilbert curves, and these curves are shown in a window using the .NET library. The theme of an exercise is a picture library used to describe families of recursively defined pictures like Escher's fishes.
- Type
- Chapter
- Information
- Functional Programming Using F# , pp. 149 - 174Publisher: Cambridge University PressPrint publication year: 2013