You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Haskell's IO monad has been a tremendous source of confusion and misconceptions over the years. At its core, it exists to solve the problem of How do we properly sequence function calls which may have side effects in an environment that assumes all functions are pure? Unfortunately, it is also many people's first exposure to the concept of monads, leading them to assume monads are all about isolating side effects. This is not the case at all; the problem IO solves is specific to IO alone. It just so happens that that problem is solvable within the monadic framework.
What is a monad?
I suppose, in the general case, this question is a little out of my depth. My grasp on category theory is tenuous at best, and any answer I tried to give would likely be wildly inaccurate. However, I am reasonably sure of what monads provide in a programming context, so let's pretend I asked that instead.
"A monad is just a monoid in the category of endofunctors. What's the problem?" ~James Iry[^1]
The problem... is that there are several problems.
It's been said that monads bear a dreadful curse. Once you finally understand what they are, you begin to see them everywhere--but somehow become completely incapable of explaining them to anyone else. Many tutorial writers have tried to break the Great Curse--the Web is lousy with bold attempts and half successes that attest to this--and just as many have failed. Well, I'm here to address the elephant in the room[^2] and tell you that I intend to break the Great Curse once and for all.
There are basically two ways a monad tutorial tends to go. One is a paragraph or two of minimal descriptions of one or two common monads (Haskell's Maybe in particular is very popular), followed by a lot of intimidating Haskell syntax trying to explain--precisely--how it all fits together. This is well