3 ms·
Pretty good article! I read the first few paragraphs and was a little scared, but the author redeemed himself with the line, "A simpler way to think about mona
by jrockway 17y ago
Pretty good article! I read the first few paragraphs and was a little scared, but the author redeemed himself with the line, "A simpler way to think about monads is as a hack to turn function composition into a way of forcing the sequencing of function calls, or the functional-programming equivalent of a shell pipeline." After that, I would agree with pretty much everything he says! (A first for an "I looked at Haskell today" article :)
A few nit-picks that come to mind; thunks and closures are related but different, every other language with thunks also calls them thunks.
Lisp is not really "based on lambda calculus" any more than any other imperative programming language; "(loop for i from 1 to 10 collect (+ i 42))" is not so different from a loop in assembler.
And finally, monads are not really a hack for making function application look like a sequence, that's already what function application does. Monads just let you run some extra code between function applications. But given that most people write stuff like, "monads are like nuclear-waste burritos inside of spacesuits" (er...), I am not going to complain about this explanation too loudly :)
- barrkel 17y agoWell... if you consider IO to be the nuclear waste of functional programming, the IO monad is a way of wrapping up that nuclear waste so tightly that it can't escape until the functional program has logically completed executing. The high-level result (of some IO type) is logically an imperative program that the functional program built using functional composition with placeholders where the IO was supposed to happen. But while I have to stretch to make this analogy, monads are sufficiently abstract that they could probably be made to fit many strained analogies...
- Xichekolas 17y agoWhen jrockway said the burrito thing, I think he was referring to the Brent Yorgey post about the "monad tutorial fallacy": http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ http://byorgey.wordpress.com/2009/01/12/abstraction-intuitio... To summarize: everyone, once they learn Haskell, comes up with their own analogy for "what monads are"... and the analogy, while it makes perfect sense to the person that came up with it, never helps anyone else because everyone gets to monads via a different route.
- eru 17y agoI have the perfect explanation for Monads: Monads are like everything that satisfies the three monad laws. (Of course this only helps mathematicians, if at all. Not mere mortals.)
- jrockway 17y ago"A monad is like a functor, except there is also a 'join' operation."
- eru 17y agoDon't forget about pointed functors in between, i.e. return.
- jrockway 17y agoYeah. My mental picture is "thing with return/pure -> thing with fmap -> thing with join". The second is a pointed functor, the third is monad. Not sure what the first is, probably because it is nearly useless :)
- eru 17y agoYou may have it backward. The mathematicians use "thing with fmap (functor) -> thing with return/pure (pointed functor) -> thing with join (monad)", as far as I know. Arrows are another generalization of Monads that goes in a direction different from functors.
- camccann 17y agoI don't see what even needs explanation. Really, monads are just a monoid object in an endofunctor category. [0] What's the problem? [1] [0] http://ncatlab.org/nlab/show/monoid#examples_6 http://ncatlab.org/nlab/show/monoid#examples_6 [1] http://james-iry.blogspot.com/2009/05/brief-incomplete-and-mostly-wrong.html http://james-iry.blogspot.com/2009/05/brief-incomplete-and-m...
- 17y ago
- eru 17y agoMonads are a hack (http://catb.org/jargon/html/H/hack.html http://catb.org/jargon/html/H/hack.html) more in sense 2, not in sense 1. 1. n. Originally, a quick job that produces what is needed, but not well. 2. n. An incredibly good, and perhaps very time-consuming, piece of work that produces exactly what is needed.
- dons 17y agoThey're also precisely the foundations of different notions of computation -- what we mean by ';' in an imperative language. So if math is a hack, then yeah. http://portal.acm.org/citation.cfm?id=116984 http://portal.acm.org/citation.cfm?id=116984 Go read Moggi.
- eru 17y ago> They're also precisely the foundations of different notions of computation Depends. Monads are too linear, in a sense, to express some computations. Arrows express some things better.