Chapter 15. Creating composable functional libraries
This chapter covers
- Designing functional combinator libraries
- Working with time-varying values
- Composing time-varying values with drawings
- Developing library for modeling financial contracts
A design principle that arises in many aspects of functional programming is compositionality. This means building complex structures from a few primitives using composition operations. We’re describing compositionality in a general sense because it can appear in countless forms. Let’s look at two examples you’re already familiar with.
We’ll begin with the F# type system: there are a few primitive types, such as integer and Boolean, as well as ways of combining them, such as using the * type constructor to build a tuple of type int * bool. If we leave out the object-oriented features of F#, we have only three ways of composing them: multiple values using tuples, alternative values using discriminated unions, and functions. We can use them to build incredibly rich types.