
Monads in Clojure - rohshall
http://www.intensivesystems.net/tutorials/monads_101.html
======
breckinloggins
> The idea behind a monad is to factor out the plumbing code so that its
> complexity is hidden, leaving only the composition of the functions visible.

 _cue light bulb coming on_

Thanks so much for this article; I've been trying to understand monads forever
now. The closest I got was the "burrito" analogy, but I always wanted a more
mathematically sound intuition.

For helpful reference, here's a collection of monad tutorials and related
pedagogy:

\- Monads are burritos [[https://speakerdeck.com/u/dimituri/p/a-monad-is-just-
a-burri...](https://speakerdeck.com/u/dimituri/p/a-monad-is-just-a-burrito)]
(slide deck)

\- No, they really aren't
[[http://byorgey.wordpress.com/2009/01/12/abstraction-
intuitio...](http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-
and-the-monad-tutorial-fallacy/)]

\- Well yeah, they kinda are [<http://blog.plover.com/prog/burritos.html>]

\- But anyway, you probably have already invented them yourself; you just
didn't realize it [[http://blog.sigfpe.com/2006/08/you-could-have-invented-
monad...](http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-
and.html)]

\- And even if you didn't, you can always learn about it from that crowd-
sourced fountain of programmer knowledge, StackOverflow (and this question
hasn't even been closed as "not constructive"!)
[<http://stackoverflow.com/questions/44965/what-is-a-monad>]

\- Of course, once you understand basic category theory, you should be set
anyway. What are you, some kind of Java programmer?
[[http://reperiendi.wordpress.com/2007/11/03/category-
theory-f...](http://reperiendi.wordpress.com/2007/11/03/category-theory-for-
the-java-programmer/)]

\- But really, a monad is just a monoid in the category of endofunctors,
what's the problem? [[http://stackoverflow.com/questions/3870088/a-monad-is-
just-a...](http://stackoverflow.com/questions/3870088/a-monad-is-just-a-
monoid-in-the-category-of-endofunctors-whats-the-problem)]

------
monkeyfacebag
I appreciate these attempts to give non-Haskellers a chance to learn Monads
but, personally, I never really grokked them until I got into Haskell. In
Haskell, Monads are defined in terms of types, thus languages without type
systems like Haskell's make the concept both more difficult to understand
_and_ less (immediately) useful. Having been through many of these tutorials
myself, I think the best way to get into Monads (as well as many other useful
constructs like Functors, Monoids and Monad Transformers) is to roll up your
sleeves and learn Haskell (Learn You A Haskell is a great and relatively quick
read). As a bonus, you'll also learn one of the most elegant programming
languages around.

This comment isn't intended as a knock against the article. I think there's a
lot of merit in using monadic constructs in languages that aren't Haskell, I
just think Haskell's type system makes understanding the concept easier.

~~~
swannodette
I disagree. The only sensible introductory text I've found about them is for
Scheme - <http://www.cs.indiana.edu/~cswords/monads.pdf>. Folks love to
emphasize the types - but how one might implement them matters just as much if
not more IMO.

Also, I've found the usage of monads as the building blocks for modular
interpreters to shed the most light on their power, utility, and limitations
(see the various papers from Steele, Wadler et al, Hudak et al, and Felleisen
et al).

~~~
monkeyfacebag
> but how one might implement them matters just as much if not more IMO

This is a false choice. Learning monads through Haskell, you get the forest
_and_ the trees! That said, I get that there are legitimate differences of
opinion and what worked for me will not necessarily work for others. I feel
like _some_ understanding of types (or categories, etc.) is necessary to fully
grok monads. Both this article and your linked paper offer some basic
explanation of the concept. Tutorials that are essentially implementations of
bind are, in fact, missing the forest for the trees.

------
brehaut
The author of this article, Jim Duey, has written some newer introductions to
monads in clojure on his new site: <http://www.clojure.net/archive.html>

------
jballanc
Just a note for anyone hoping to follow along at home: clojure.contrib has
been deprecated and the various parts have either moved or been left to bitrot
on the vine. Pertinent to this article, "clojure.contrib.monads" is now
"clojure.algo.monads".

You can find out what happened to the rest of clojure.contrib here:
[http://dev.clojure.org/display/design/Where+Did+Clojure.Cont...](http://dev.clojure.org/display/design/Where+Did+Clojure.Contrib+Go)

------
michaelcampbell
I met the author (after having seen his video of this subject) at clojure/conj
2011. Fascinating guy, and can really explain this stuff in more or less terms
I can understand.

I don't use it enough to "get it" so I have to re-learn it every time I feel
the need to, but this is the go-to spot for me.

------
ozataman
Nice article. On the other hand, in a slightly joking manner, I really wonder
how some people can live with 8-space tabs with 8+ levels of indentation!

~~~
kleiba
The lisp code in the article doesn't do indentation by a fixed number of
spaces. It indents syntactically, i.e., aligns depending on the current depth-
level of the s-expression).

------
tsewlliw
It IS really nice to see something on those mysterious monads not written in
haskell. I got hung up early into the article though, where the author says
something to the effect of "the monad hides the complexity", and that seemed
like a silly goal. I need to make another pass at it.

~~~
chc
Hiding complexity is almost the whole point of most programming languages and
a big reason why most of the popular library and frameworks exist. Computer
programs are fiendishly complex things, and they're only getting more so as
time goes on (now we have several independent processors doing complex things
simultaneously in the service of even larger complex things). A lot of
software is so big that even most of its components are too much to fit in
your head at once. So I think hiding complexity is a pretty sensible goal.

------
sutro
I remember how happy I was the first time I really grasped my nads.

