background preloader


Facebook Twitter

Monads Are Not Metaphors. 27 Dec 2010 This article is also available in Japanese.

Monads Are Not Metaphors

I am about to break a promise. Almost three years ago, I promised myself that I would never write an article about monads. There are too many such articles already; so many, in fact, that people are often confused by the sheer proliferation. Everyone seems to have a different take on the subject, meaning that those attempting to learn the concept for the first time are stuck trying to reason out the commonalities between burritos, space suits, elephants and desert Bedouins. I’m not going to add to this menagerie of confusing analogies. Math (or not) Here’s the thing about monads which is hard to grasp: monads are a pattern, not a specific type. Just as a quick Ruby refresher, we can rewrite this code in the following way: Ruby has this neat convention (which is shared by most modern languages) which causes the final expression in a method to be turned into the implicit return statement.

Still with me? You Could Have Invented Monads! The adventures of a Java developer in MonadLand(aka Scala monads for dummies) Copyright © 1999-2012, LLC. All rights reserved. *One FREE .COM, .CO, .NET or .ORG with purchase of a new 12-, 24- or 36-month website builder plan. Plus ICANN fee of $0.18 per domain name per year. You must add the domain name into your cart before purchase, and you must select a domain term length equal to or less than the term length of your website builder plan to qualify for the free domain offer. If you purchase a domain name for a term longer than the term of the website builder plan, you will be charged for the additional registration term at the then-current rate. . + New .COMs $7.99/yr plus 18 cents/yr ICANN fee. Monads for the Curious Programmer, Part 1 «   Bartosz Milewski’s Programming Cafe.

The Monad is like a bellows: it is empty yet infinitely capable.

Monads for the Curious Programmer, Part 1 «   Bartosz Milewski’s Programming Cafe

The more you use it, the more it produces; the more you talk about it, the less you understand. –Monad Te Ching I don’t know if I’m exaggerating but it seems like every programmer who gets monads posts a tutorial about them. (And each post begins with: There’s already a lot of monad tutorials on the Internet, but…) The reason is that getting monads it’s like a spiritual experience that you want to share with others. When facing a monad, people often behave like the three blind men describing an elephant. Monads are hard to describe because they don’t correspond to anything in our everyday experience. But first, let me answer the pertinent question: Monads enable pure functional programmers to implement mutation, state, I/O, and a plethora of other things that are not functions. The thing is, all those non-functional things that we are so used to do in imperative programming are also sources of a lot of troubles.