|
|
|
|
|
by svachalek
4807 days ago
|
|
Except that what it looks like isn't actually what it's doing (made even clearer by the a <- a example). I like the Maybe concept and non-nullable types; I just think being able to overload operators like "=" and ";" in C++ and Haskell is optimizing writability over readability and in most cases, readability is by far the more important attribute. |
|
In this case, think of Maybe as a box containing one or zero instances of a type. For Maybe
Lists are 'boxed' values containing any number of elements The monadic semantics for lists means this returns the sum of each combination of values, namely [11,21,12,22]. This is essentially like a database join, which is why a monadic structure was used for LINQ.For Promises
This returns a new promise containing the sum of the result of two promises instead of using callbacks.Essentially all these types live in a Maybe/List/Promise box. There are many more examples. The nice thing about monads is that the semantics of how these things work is abstract enough to allow a variety of interpretations, but constrained enough (by the Monad laws) that you get a nice intuition of how things work after using a few different instances.