News for hackers. Stuff that matters.
Re:Ask HN: ELI5 What Is a Monad? by assbuttbuttass on Monday November 14, 2022 @11:04AM (#33596022)
A monad is a box that can contain a value. You can run an operation on the value inside the box.

An example of a monad is the Option monad: the box can either contain a value or it can be empty. The monad operation in this case modifies value in the box, or does nothing if the box is empty.

Another example is the IO monad, you can think of the box in this case as representing "the state of the world". The monad operation can modify the value in the box, but it can also write in sharpie on the outside of the box (perform IO)

In general a monad is any data structure where you have some boxed value and you can operate on the value without opening the box.

Re:Ask HN: ELI5 What Is a Monad? by bluefirebrand on Monday November 14, 2022 @12:09PM (#33597253)
This seems like the most clear explanation of what a monad is that I've ever seen. Thanks for this!
Re:Ask HN: ELI5 What Is a Monad? by badpun on Monday November 14, 2022 @02:48PM (#33599882)
I'm not an FP expert by any means, but isn't having a flat-map operation (i.e. being able to combine two monads together, with result being another monad) a defining part of being a Monad?
Re:Ask HN: ELI5 What Is a Monad? by Tainnor on Monday November 14, 2022 @08:21PM (#33604017)
Yes.

"A value in a box" is more like a metaphor for a functor.

The key part about monads is that you can "merge the boxes" (to strain the analogy). Or, as I'd prefer to think about it, to merge different effects.