Live data from Hacker News

Ask HN: What is a monad?

news.ycombinator.com

51–55 of 55 posts

Re: Ask HN: What is a monad?

#51

Earlier quoted context omitted.

Unfortunately "monad" gets used in a few contexts unrelated to the sense the OP is asking about. Similarly, the (cancelled) TV series Caprica recently started using "monad" to mean "monotheist".

On the other hand, it seems that if one is willing to propose a similarity between one of the cornerstones of rationalism and the misuse of "monad" by a fictional character on a canceled television series, one might be more open to seeing more direct lines of intellectual descent from an inventor of the calculus to functional programming. The embedded type system of a programmatic monad remains unchanged despite the…

[deleted]

Re: Ask HN: What is a monad?

#52
post #42

Earlier quoted context omitted.

Each of your statements seems plausible, even profound in itself. Then I try to combine them and my head explodes. You don't need to understand Monads to understand Haskell but they're how you print "Hello world"?? Yeah. Your other example also seem pithy and worthy, and again leave me feeling like the result is utterly opaque. You've shown goodness and power and all but it feels like you're holding the real definiti…

No, actually, i've read dozens of explanations, i went metalinguistic and read discussions about discussions of monads, and this guy is totally correct, the ONE SINGLE most important thing to know about a monad, it would seem, is that you are not required to know what a monad is to use it.

[deleted]

Re: Ask HN: What is a monad?

#53
post #42

Earlier quoted context omitted.

Each of your statements seems plausible, even profound in itself. Then I try to combine them and my head explodes. You don't need to understand Monads to understand Haskell but they're how you print "Hello world"?? Yeah. Your other example also seem pithy and worthy, and again leave me feeling like the result is utterly opaque. You've shown goodness and power and all but it feels like you're holding the real definiti…

No, actually, i've read dozens of explanations, i went metalinguistic and read discussions about discussions of monads, and this guy is totally correct, the ONE SINGLE most important thing to know about a monad, it would seem, is that you are not required to know what a monad is to use it.

[deleted]

Re: Ask HN: What is a monad?

#54
post #44

Earlier quoted context omitted.

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?

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: Yo…

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.

Re: Ask HN: What is a monad?

#55
I'll have my stab at making a short explanation without code or lots of technical stuff. So here's some handwaving that may contain mistakes:

Monads are sequential processes, which are combined to make bigger processes. getLine is a monad, so is putStrLn "hello". You can combine two monads into a bigger monad using the >>= operator, which would be the "means of combination" which is extensively discussed in the Structure and Interpretation of Computer Programs lectures. Simplest monad program I can think of is echo = getLine >>= putStrLn.

I learned monads by doing simple stuff like guess the number and hangman, first writing them in the do-notation (syntactic sugar for a mini-imperative language) and then converting that to concrete notation using >>=.

Monads are not only useful for IO, but also other sequential processes such as parsing, pretty printing, binary file io and stateful inside but functional outside algorithms (ST monad).

Disclaimer: this was written by a Haskell newb, recently introduced to the wonderful world of Monads.

Post reply on HN