Elm creator Evan Czaplicki illustrates it by way of the Monad:
https://youtu.be/oYk8CKH7OhE?t=1454 from 24:14 until 29:39.
I've also updated that section of the article, to provide some justification for my wish there, including a few more illustrative backing sources.
A monad is a data structure that holds one value, but that value may be of one of several types. It implements a `map` function which allows conversion to the same monad with different set of types, eg there is some function `map` defined as :
fn map ( f : Tn -> Un, Monad<T1, T2, ..., Tn, ... TN>) -> Monad<T1, T2, ..., Um, ..., TN)
for each type the value may be in the Monad.Two commonly used examples are the Optional and Result monads. An Optional is either a value of type T, or the empty type None. A Result is a value of type T or some error E.
The utility of monads is their ability to chain operations. With optionals, you can map the results of functions that may or may not return results without handling the None case explicitly. With Result types you may chain operations that return errors, and handle both the successes and cases where you need to convert errors.
Monads can be expressed in many languages, but they make the most sense in languages with algebraic data types (to express a value is one of a set of possible types, aka union/sum types) and first-class functions (where functions can be passed as an argument, or else implementing `map` may be difficult).
The mathematical parlance is really harmful to their adoption because as an abstraction, monads are stupidly easy to use.
Basically the point of a monad is to depend on the output of another monad data type of its kind — e.g. it can take an IO String and use the encapsulated String value to produce another IO X. This would be IO (IO X) without the flatmap, or the bind function that can remove this double encapsulation.
In my definition `map` is serving the purpose of your flatmap, I didn't mean to imply double encapsulation.
https://youtu.be/oYk8CKH7OhE?t=1454 from 24:14 until 29:39.
Haskell/FP/Math purists would probably balk at the oversimplification. But introducing intimidating concepts by way of such oversimplification (without entirely missing the target) is precisely the point! Beginners just need a very rough and coarse grained overview, so they are able to gain some basic familiarity with the concept. That gives them some already-familiar conceptual knobs to hang further details on, reduces fear, and inspires curiosity to investigate further.
Rust: Result::and_then()
Scala: Option.flatMap()
JS: Promise.then()
...
I agree it can take some time to discover the similarities between these interfaces. But a monad is just that. It's so simple that we are blind to see.Unfortunately, it requires a sufficiently advanced language to express the concept of Monad. You need at least higher-kinded types and means to describe behaviors of HKTs.
Can you understand or describe monads in a less powerful language, say Rust? Definitely!
But will you appreciate the power that monads give you in Rust? Probably no.
> I'd prefer math and programming shared terminology
there are many kinds of maths, from which one of them should they share terms?If you pick none at all, well, you mostly just get the last two.
Well, the author (and many others) wants them to allow less abstractions then.
https://youtu.be/oYk8CKH7OhE?t=1454 from 24:14 until 29:39.
but if my program happens to draw the sword of math beware! I am never going to understand Haskell, or should I say ∵⌷⊃○⌽⍉⌊⍟⊖∇⍫⍒∆
a <$> b
instead of (1 char longer) fmap a b
or (3 chars longer) a `fmap` b
I understand fmap, but <$> tripped me up for an embarrassingly long time when trying to read Haskell code. In any other language, I'd do a web search for the function I didn't understand, to learn more about it, but that doesn't work here because most search engines don't handle symbols well. You have to know to use Hoogle. But someone who's trying to teach themselves Haskell isn't just going to know that. Learning Haskell doesn't have to be harder than learning another language, but it does require inordinately more hand-holding.I'm sure I'm not the only one. This is something I would call an "inessential weirdness"[0] of Haskell. There is a whole host of others— <>, $, and >>= are some from the Prelude alone; it becomes especially tricky when people don't use explicit or qualified imports.
[0]: A term I learned from this excellent talk, https://harihareswara.net/texts/inessential-weirdnesses-in-f... which you can watch at https://media.libreplanet.org/u/libreplanet/m/inessential-we...
https://www.google.com/search?hl=en&q=%3C%24%3E
https://stackoverflow.com/questions/37286376/what-does-mean-...