What, no one is giving the standard answer of "a monad is a monoid in the category of endofunctors?" A category is something like a set, but combining the objects with allowed operations. (How very OOP!) The available functions are first-class citizens (called arrows). The objects are the domains and ranges of the arrows, and their internal structures are not exposed. Arrow composition is associative when it is defin…
The paragraph starting "As each object in this category..." made no sense to me. I can explain the what a monoid in the category of endofunctors is, how it relates to a Haskell monad and maybe you can explain what you meant. OK, a monoid in the category of endofunctors is an endofunctor F together with a natural transformation (the multiplication of the monoid) from F composed with F to F, and another natural transfo…
Ask HN: What is a monad?
41–50 of 55 posts
Re: Ask HN: What is a monad?
#42Monads are red herrings , if what you're interested in is getting started with functional programming (or even Haskell specifically). It's an unfortunate flaw in the Haskell literature that makes it seem like you have to grok monads to learn Haskell; you don't. Monads enable syntactic sugar . If you're getting started with Haskell, you'll notice that when you write code that does I/O, you use a weird imperative-looki…
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…
Re: Ask HN: What is a monad?
#43Monads are red herrings , if what you're interested in is getting started with functional programming (or even Haskell specifically). It's an unfortunate flaw in the Haskell literature that makes it seem like you have to grok monads to learn Haskell; you don't. Monads enable syntactic sugar . If you're getting started with Haskell, you'll notice that when you write code that does I/O, you use a weird imperative-looki…
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…
I didn't mean to "hold the real definition behind my back", just felt that others in this thread had explained the definition better than I could. I also wanted to make the point that the definition is not that important unless you actually want to implement your own monad.
You don't need to understand Monads to understand Haskell but they're how you print "Hello world"??
Yes, there's no contradiction here. The idiomatic and easiest way to write Hello World in Haskell involves some unusual, but fairly intuitive, imperative-looking syntax. That syntax only works because the Haskell IO API is monadic, but you really don't need to know that, nor to understand what a monad is, in order to print Hello World.
LINQ is very similar to Haskell's do-notation, and LINQ providers (LINQ-to-Objects, LINQ-to-SQL etc) are monadic, but you don't need to know what a monad is to write "from u in users where u.age > 21 select u.name". If you want to write your own LINQ provider, though, it's probably worth knowing the monad laws.
Re: Ask HN: What is a monad?
#44Earlier quoted context omitted.
A monad is a type that has certain associated functions — to wrap values in the monad and do calculations on what's inside. The type itself obviously cannot execute code, but the associated functions obviously do. Monads can be used to implement exceptions. As an example, lists are monads. The operator for doing calculations with the value in a monad is >>= (pronounced "bind"). To double every item in an array, you c…
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?
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?
#45What, no one is giving the standard answer of "a monad is a monoid in the category of endofunctors?" A category is something like a set, but combining the objects with allowed operations. (How very OOP!) The available functions are first-class citizens (called arrows). The objects are the domains and ranges of the arrows, and their internal structures are not exposed. Arrow composition is associative when it is defin…
Re: Ask HN: What is a monad?
#46Monads are red herrings , if what you're interested in is getting started with functional programming (or even Haskell specifically). It's an unfortunate flaw in the Haskell literature that makes it seem like you have to grok monads to learn Haskell; you don't. Monads enable syntactic sugar . If you're getting started with Haskell, you'll notice that when you write code that does I/O, you use a weird imperative-looki…
Upvoted for excellent explanation. Thanks.
Re: Ask HN: What is a monad?
#47Monads are red herrings , if what you're interested in is getting started with functional programming (or even Haskell specifically). It's an unfortunate flaw in the Haskell literature that makes it seem like you have to grok monads to learn Haskell; you don't. Monads enable syntactic sugar . If you're getting started with Haskell, you'll notice that when you write code that does I/O, you use a weird imperative-looki…
Upvoted for excellent explanation. Thanks.
Re: Ask HN: What is a monad?
#48A cheap and unexciting trick for passing a value through a couple of functions. (Monads are cool, but it's important to understand that there's nothing, nuttin', whatsoever fancy about them, so I like to call them a "cheap trick".) This is a good intro: http://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/ba... Be sure to mentally replace "monad" with "warm fuzzy thing" when reading it and it should make sense.
Actually, the effects of that trick are nothing less than exciting. For example, that trick allows you to pass information from future (one of Wadler examples).
Re: Ask HN: What is a monad?
#49Monads are red herrings , if what you're interested in is getting started with functional programming (or even Haskell specifically). It's an unfortunate flaw in the Haskell literature that makes it seem like you have to grok monads to learn Haskell; you don't. Monads enable syntactic sugar . If you're getting started with Haskell, you'll notice that when you write code that does I/O, you use a weird imperative-looki…
Upvoted for excellent explanation. Thanks.
Re: Ask HN: What is a monad?
#50Earlier 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…