It's not a bad example but lacking generality and more importantly explicit types.
It's really all about connecting types like LEGO blocks, so the important thing is to show the type signatures.
"bind" is the function required from Haskell's Monad typeclass, but not a good choice to explain monads. It's much cleaner to explain monads as functors with "join" and ("inject" aka return).
map :: (a -> b) -> (M a -> M b)
join :: M (M a) -> M a
inject :: a -> M a
With these guys you can easily compose "dirty" asymmetric operations like (readFile :: FilePath -> IO Bytes)
Re:Functional Programming Jargon
by jethrolarson on Thursday July 28, 2016 @01:28AM
(#12178485)
It's hard to capture monad in a paragraph and a couple examples. The utility of chain/flatmap doesn't get too interesting until you apply it to the Option Type or Promises but I didn't want to require readers to come with knowledge of them. Maybe a promise-based example isn't asking too much though
Also, this may well be the thing that finally helps me understand what the crap Monads are.