Hacker News new | past | comments | ask | show | jobs | submit login

The simplest but still most versatile one is probably fmap (also knowns as <$>) which lets you use a function on whatever is inside the burrito:

(+1) <$> Just 1 → Just 2 (+1) <$> getIntFromThatUserThatOnlyTypes1 → IO 2 (+1) <$> [1,2] → [2, 3] ((+1) <$> ask) 1 → 2

Want let a function eat several burritos without making a mess? Keep your burritos apart with <>:

take <$> Just 2 <> Just "abc" → Just "ab"

etc.

You can be quite productive without moving past the burrito analogy.




No. If you attempt to write monad-generic code using the burrito analogy you will inevitably write broken code, causing serious problems for other users and/or your future self.

Burritos may be a good analogy for some subset of monads, e.g. collections, but they are not a good analogy for monads in general: the function you pass to fmap may be executed now or later, zero, one, or many times, before or after a function you pass to a later fmap.


Nah, like any bad analogy, it can be stretched :) Once you've moved past the "lies-to-children[1]" version, you can ascend to the real meat of the burrito: https://blog.plover.com/prog/burritos.html

And once you've fully grokked burritos in terms of monads, you can finally reach that zen level where you solve your problems without even a single line of code (because you've started working at the burrito shop instead: http://chrisdone.com/posts/monads-are-burritos ).

[1] https://en.wikipedia.org/wiki/Lie-to-children


too late to edit, but that should look like

    (+1) <$> Just 1 → Just 2 

    (+1) <$> getIntFromThatUserThatOnlyTypes1 → IO 2

    (+1) <$> [1,2] → [2, 3]

    ((+1) <$> ask) 1 → 2
and

    take <$> Just 2 <*> Just "abc" → Just "ab"
as if the operator line noise wasn't bad enough already :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: