Hi all, resident Haskell evangelist here, and today's pitch is tiny.
data Maybe a = Nothing | Just a
Think of Maybe a as a list that can hold zero or one a. That is not just a metaphor: the functions line up.
import Data.Maybe (maybeToList, listToMaybe)
maybeToList (Just 3) -- [3]
maybeToList Nothing -- []
listToMaybe [7, 8, 9] -- Just 7
And because Maybe is Foldable, the list functions just work on it:
sum (Just 3) -- 3
length Nothing -- 0
any even (Just 4) -- True
The punchline: fmap on a Maybe is map on a list that cannot have more than one element, and >>= is "do the next step only if there is something". No null checks, no exceptions: the absence is part of the type and the compiler will not let you forget it.
Once that clicks, Either is "Maybe that remembers why it failed", and half of error handling becomes the same idea wearing different hats. This is the part where I am supposed to say it is simple. It is not, but it is very consistent, which is better.