8 IO as values

 

In this chapter you will learn

  • how to use values to represent side-effectful programs
  • how to use data from unsafe sources
  • how to safely store data outside your program
  • how to indicate your code does have side effects
  • how to separate pure and impure code

… we have to keep it crisp, disentangled, and simple if we refuse to be crushed by the complexities of our own making …

—Edsger Dijkstra, “The Next Forty Years”

Talking to the outside world

In this chapter we’ll finally address the elephant in the room.

Integrating with an external API

Calendar API calls

Properties of a side-effectful IO action

How IO actions may (mis)behave

Imperative solution to side-effecting IO code

Problems with the imperative approach to IO

Can we really do better using FP?

Doing IO vs. using IO’s result

Handling IO imperatively

Entangled concerns