How Monads are considered pure?

One way to think of this is that a value of type IO a is a “recipe”, containing a list of instructions that if performed would have side effects. Constructing that “recipe” though, does not have any side effects. So a haskell program (whose type is IO ()) is basically a computation that constructs such a recipe. Importantly, the program does not execute any of the instructions in the recipe. When the recipe is completed the program terminates. Then the compiler (or interpreter) takes that recipe and executes it. But the code that the programmer wrote is not running anymore, so the instructions in the recipe are executed outside the scope of the program.

Leave a Comment