News for hackers. Stuff that matters.
Re:Ask HN: What is a monad? by StavrosK on Sunday December 12, 2010 @05:05PM (#1998189)
Hmm, I see. The problem with my understanding it is that people are describing its properties and I have to build the mental model from them.

Are Python list comprehensions monads?

Re:Ask HN: What is a monad? by chc on Sunday December 12, 2010 @11:38PM (#1999341)
Well, it's the type itself that's a monad. So the question would be, are Python lists monads thanks to list comprehensions? And the answer is: Kind of. The idea of a monad in functional programming is that it's a generic type that can have a lot of different implementations.

The two operations that must be defined for a monad are:

• Return: You pass any value and it returns a monad encapsulating that value

• Bind: You pass a function taking an argument of the type wrapped by the monad and returning another value wrapped in the monad, and it returns a value of the monad

With these two operations, you can accomplish a surprising range of tasks. Python borrowed list comprehensions from Haskell, where they are based on monads — but in Python, they're kind of orphaned from their monadic roots.

Re:Ask HN: What is a monad? by StavrosK on Monday December 13, 2010 @09:20AM (#2000502)
This makes it much clearer, thanks. Those two operations weren't mentioned anywhere else that I saw, and they are very helpful in explaining what monads are.