11 Designing functional programs

 

In this chapter you will learn

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

What I cannot create, I do not understand.

—Richard Feynman

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 some very old programming advice: first make the solution work, then make it work correctly, and, only then, think about making it fast. Following are the requirements, which, understandably, are a bit more involved than what we were used to.

Modeling using immutable values

Business domain modeling and FP

Data access modeling

Separation of concerns

Coding to the interface

A bag of functions

Business logic as a pure function

Separating the real data access concern

SPARQL query language

Integrating with APIs using imperative libraries and IO

1. Creating the SPARQL query

2. Connecting to and querying the Wikidata service

3. Extracting and parsing the query results

Connecting to the server