12 Functional input/output

 

In this chapter

    • Applying effects safely from inside contexts
    • Combining effects for success and failure
    • Safely reading data
    • Using the IO type and imperative-like control structures
    • Combining IO operations

    So far you’ve learned how to write safe programs that haven’t produced any usable results. You’ve learned how to compose true functions to build more powerful functions. More interestingly, you’ve learned how to use nonfunctional operations in a safe, functional way. Nonfunctional operations are operations producing side effects such as throwing exceptions, changing the outside world, or 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. Here are some examples of computational contexts you’ve created in previous chapters:

    12.1 What does effects in context mean?

    12.1.1 Handling effects

    12.1.2 Implementing effects

    12.2 Reading data

    12.2.1 Reading data from the console

    12.2.2 Reading from a file

    12.3 Testing with input

    12.4 Fully functional input/output

    12.4.1 Making input/output fully functional

    12.4.2 Implementing purely functional I/O

    12.4.3 Combining I/O

    12.4.4 Handling input with IO

    12.4.5 Extending the IO type

    12.4.6 Making the IO type stack-safe

    Summary