Chapter 13. Functional input/output
This chapter covers
- Applying effects safely from inside contexts
- Adding effect application to Result and List
- Combining effects for successes and failures
- Reading data safely from the console, from file, or from memory, with the Reader abstraction
- Handling input/output with the IO type
So far, you’ve learned how to write functional programs that haven’t really produced any usable results. You learned how to compose true functions to build more-powerful functions. More interestingly, you learned how to use nonfunctional operations in a safe, functional way. Nonfunctional operations are operations producing side effects, like throwing exceptions, changing the outside world, or simply depending on the outside world to produce a result. For example, you learned how to take an integer division, which is a potentially unsafe operation, and turn it into a safe one by using it inside a computational context.
You’ve already encountered several such computational contexts: