11 Designing Functional Programs

 

In this chapter you will learn how to

  • design functional real-world applications
  • model more complicated requirements as types
  • integrate with real data-source APIs using IO
  • avoid resource leaks
  • cache query results to speed up the execution

What I cannot create, I do not understand.

— Richard Feynman

11.1  Make it work, make it right, make it fast

This quote has a long history, but the presented formulation is attributed to Kent Beck.

It’s time to put all the knowledge you’ve gained to a good use and implement something tangible! We will use all the functional tools and techniques we learned to follow the very old programming advice: first make the solution work, then make it work correctly, and only then think about making it blazingly fast. Here are the requirements, which understandably are a bit more involved than what we were used to:

11.2  Modeling using immutable values

11.3  Business domain modeling and FP

11.4  Data access modeling

11.5  A bag of functions

11.6  Business logic as a pure function

11.7  Separating the real data access concern

11.8  Integrating with APIs using imperative libraries and IO

11.9  Following the design

11.10    Implementing input actions as IO values

11.11    Separating the library IO from other concerns

11.12    Currying and inversion of control

11.13    Functions as values

11.14    Connecting the dots

11.15    We made it work

11.16    Making it right

11.17    Resource leaks

11.18    Handling resources

11.19    Using a Resource value

11.20    We made it right

11.21    Coffee Break: Make it fast

11.22    Coffee Break Explained: Make it fast

11.23    Summary