3 ms·
> I don't understand how people keep failing to understand monads. Maybe it's the line noise operator `>>=' ? For me at least, the mathematics line-noise is a
by _delirium 17y ago
> I don't understand how people keep failing to understand monads. Maybe it's the line noise operator `>>=' ?
For me at least, the mathematics line-noise is a bigger issue, and it made more sense once I ignored it. As a programming construct, monads seem quite understandable to me, even clever. But many of the explanations, especially earlier ones, started out with a type-theoretic explanation with links to category theory...
In particular, I was under the misimpression for years, because of it being presented that way, that monads were essentially of interest only for people who were hung up on type-checking: that they were a solution to how to make the type-checking go through on a certain class of problems, by lifting an underlying type into the Monadic type and getting it back out again. As someone who mainly uses dynamically typed languages, this didn't seem of interest, since in Lisp, I don't care if the type-checking goes through or not. It was probably years later that I figured out they had some non-type-related programming benefit.
- anonymousDan 17y agoWhich are? I've read somewhere they help improve the modularity of your code, is this what you're referring to?
- chousuke 17y agoFunctional programming is very focused on composing operations. Function composition is an obvious example, but it is not the only one. As far as I understand monads, they allow you to write generic operations separate from the logic needed to compose those operations. Inspired by this article. and in a fit of temporary insanity, I implemented a simple monad protocol and the Maybe and List monads in Clojure. It's not fit for use, but it was fun to write. http://gist.github.com/312281 http://gist.github.com/312281 It may not be immediately evident what is being composed there, but if you look at lift, it breaks the multi-argument "+" operator into several partial applications and composes each of those under the given monad, giving interesting results. This was necessary to maintain support for a variable number of arguments. Note that the code uses features only available in the git master branch, so you will need a snapshot build to run it.