3 ms·
On this page I have heard so far: Monads are... * just a way of defining a list * very much not that * dealing with side effects using functions Apparently
by Brian_K_White 5y ago
On this page I have heard so far: Monads are...
* just a way of defining a list
* very much not that
* dealing with side effects using functions
Apparently the article is spot on. The concept may be understood, but may not be communicated.
It's quite interesting seeing the phenomenon play out just as described.
- Izkata 5y agoThough I'm not certain I do understand monads, this is what I eventually made sense to me from various tutorials: A container datatype that abstracts control flow in a composable way.
- Koshkin 5y agoOne popular example of a monad is a type constructor that extends the given type - a “wrapper”, if you will, where a value can be wrapped in a trivial way (e.g. x -> {x} or x -> x?), and a double wrapping can be trivially unwrapped (“naturally transformed”) into a single one: {{xyz}} -> {xyz}. (Note that unwrapping the last remaining layer will not be always possible - e.g., while {x} -> x does indeed make sense, {x, y, z} -> … or x? -> x do/may not.)
- nybble41 5y ago> where a value can be wrapped in a trivial way (e.g. x -> {x} or x -> x?) > and a double wrapping can be trivially unwrapped (“naturally transformed”) into a single one: {{xyz}} -> {xyz} You've described the "pure" and "join" operations (in Haskell terms), which are two of the three requirements for a monad. The third and final requirement is that there must be a way to lift an arbitrary function on plain values to work on "wrapped" values: (x → y) → ({x} → {y}).
- mbrodersen 5y agoYep agree. I actually understand Monads and have used them in Haskell but I still 100% agree with you. One of the problems is that understanding Monads is 100% needed in purely functional languages but not in non-pure functional languages. I have never used Monads outside of Haskell because it doesn’t make sense to use them in C++/Java/C#.