3 ms·
Here's a couple: Monads are so pervasive that multiple languages have determined that they deserve special syntax (see: Haskell's do-notation, OCaml's let-synt
by thedufer 9y ago
Here's a couple:
Monads are so pervasive that multiple languages have determined that they deserve special syntax (see: Haskell's do-notation, OCaml's let-syntax). Those syntaxes play nicely with a ton of seemingly-different types, such as promises, options (maybes/nullables), lists, monadic error handling (either, or_error), etc.
On a similar note, recognizing the structure of monads has in the past allowed me to abstract things in an interesting way. For example, say I have a dict lookup function (takes a key, returns a value) and I want to build a bunch of useful functions on top of that. But we want to use them in many different contexts - the dict might be remote or locally in memory (promises vs. not) and we may or may not be in a test context (monadic vs exception-based error-handling). By recognizing that we can just abstract over monads, we can easily handle these 4 cases (promise, promise+error monad, error monad, unit monad).
- jw- 9y agoBy OCaml's let syntax do you mean this: https://blog.janestreet.com/let-syntax-and-why-you-should-use-it/ https://blog.janestreet.com/let-syntax-and-why-you-should-us...? You can also add F# computation expressions to the list!
- thedufer 9y agoYes, that's what I mean by let syntax. The implementation and more description can be found at https://github.com/janestreet/ppx_let https://github.com/janestreet/ppx_let I failed to find F# computation expressions, probably because I searched for the word "monad" which they seem to be avoiding, but that's another great example.
- noblethrasher 9y agoAlso, LINQ as realized in C# and VB. Crucially, `SelectMany` is just monadic bind.