8 IO as Values
In this chapter you will learn how to
- use values to represent side-effectful programs
- use data from unsafe sources
- safely store data outside your program
- indicate your code does side effects
- 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”
8.1 Talking to the outside world
In this chapter we’ll finally address the elephant in the room.
Q I now see how pure functions and trustworthy signatures can help me write better, more maintainable software. But let’s be honest. We will always need to get something from the outside: be it an API call or fetching things from a database. Additionally, almost every application in the world has a state that needs to be persisted somewhere. So isn’t this pure function concept "a bit" limited? A We can talk with the outside and still use pure function goodies! The intuition here is exactly the same as with error handling (chapter 6) and modeling requirements as types (chapter 7). We represent everything as values of descriptive types! |
|