How it works...

We have been using IO and functions related to IO in a limited way in our previous recipes. The usage was limited to printing the output using either putStrLn or print. We should spend some time to understand what IO is and how it is inevitable for a Haskell program. 

Haskell works with pure functions without side effects. It means that the evaluation of pure functions does not affect the outside world in any way. To be able to interact with the outside world, the outside world would need to contain memory, a console, file I/O, networking, and so on. The IO monad enables a Haskell program to interact with the outside world. IO monad is the gateway for pure Haskell functions to the outside world. 

By interacting with IO, Haskell ...

Get Haskell Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.