Build up your monad intuition… in JS
Most people start to grasp monads with the so called “wrapped metaphor”. It works well with List, Either a and Maybe, but it can become a problem with other monads, like IO for instance. If you have a wrapped value, why wouldn’t you be able to extract it?
A more general intuition could be “computational context which encodes sequentiality”… which doesn’t make sense until it does.
I’ve found the best way to get rid of the intuition of wrapped values is by looking at how the continuation monad works. After all, it’s The Mother of all Monads.
A few days ago, I came upon an article about Monads in PHP by Anthony Ferrara, which was quite interesting (I have a sweet spot for monads in php). Unfortunately, the implementation proposed in the article had two issues:
- fmap and bind are conflated
- the monad interface has an extract method
Please note you need a basic understanding of monads to play with it. Else, it could be a bit daunting.
Originally published at blog.clement.delafargue.name on December 16, 2014.