Chapter 16. Developing reactive functional programs
This chapter covers
- Reacting to events and declaring them in F#
- Working with events as first-class values
- Programming GUIs using asynchronous workflows
- Using message passing concurrency
This final chapter is about reacting to external events, such as user input. We’re also going to discuss another F# feature that can be used for creating concurrent programs. Although these sound like unrelated topics, we’ll see similarities as we explore them. All of the libraries and examples we’ll see in this chapter share a similar architecture, so let’s first look at the reactive architecture in general.
A lot of the code we write (in both imperative and functional programming) assumes that it’s in the driving seat—that we’re in control of what happens at each step. This model often breaks down for UIs. A Windows application needs to handle a variety of UI events; it may also have to respond to the completion of an asynchronous web service request or background task. The execution of this type of application is controlled by the events, and the application is concerned with reacting to them. For this reason, this principle is sometimes called inversion of control and is sometimes lightheartedly referred to as the Hollywood Principle.[1]
1 “Don’t call us, we’ll call you.”