Question

While learning Haskell I have faced a lot of tutorials trying to explain what are monads and why monads are important in Haskell. Each of them used analogies so it would be easier to catch the meaning. At the end of the day, I have end up with 3 differents view of what a monad is:

View 1: Monad as a label

Sometimes I think that a monad as a label to a specific type. For example, a function of type:

myfunction :: IO Int

myfunction is a function that whenever is performed it will yield an Int value. The type of the result is not Int but IO Int. So, IO is a label of the Int value warning the user to know that the Int value is the result of a process where a IO action has been made.

Consequently, this Int value has been marked as value that came from a process with IO therefore this value is "dirty". Your process is not pure anymore.

View 2: Monad as a private space where nasty things can happen.

In a system where all the process are pure and strict sometimes you need to have side-effects. So, a monad is just a little space that is allow to you for doing nasty side-effects. In this space your are allow to escape the pure world, go the impure, make your process and then come back with a value.

View 3: Monad as in category theory

This is the view that I don't fully understand. A monad is just a functor to the same category or a sub-category. For example, you have the Int values and as a subcategory IO Int, that are the Int values generated after a IO process.

Are these views correct? Which is more accurate?

No correct solution

Licensed under: CC-BY-SA with attribution
scroll top