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.

15.1. Approaches for composable design

15.1.1. Composing animations from symbols

15.1.2. Giving meaning to symbols

15.1.3. Composing values

15.1.4. Composing functions and objects

15.2. Creating animated values

15.2.1. Introducing functional animations

15.2.2. Introducing behaviors

15.2.3. Creating simple behaviors in C#

15.2.4. Creating simple behaviors in F#

15.3. Writing computations with behaviors

15.3.1. Reading values

15.3.2. Applying a function to a behavior

15.3.3. Turning functions into “behavior functions”

15.3.4. Implementing lifting and map in C#

15.4. Working with drawings

15.4.1. Representing drawings

15.4.2. Creating and composing drawings

15.5. Creating animations

15.5.1. Implementing the animation form in F#

15.5.2. Creating animations using behaviors

15.5.3. Adding animation primitives

15.5.4. Creating a solar system animation

15.6. Developing financial modeling language

15.6.1. Modeling financial contracts

15.6.2. Defining the primitives