4 ms·
I don't believe monads are worth the bother without some syntactic sugar. Without sugar, it is just a sequence of operations converted into a chain of nested la
by olavk 11y ago
I don't believe monads are worth the bother without some syntactic sugar. Without sugar, it is just a sequence of operations converted into a chain of nested lambdas with one lambda for each operation. Cool, but far to convoluted to write for any real-world programs.
The attempts to introduce monads in other languages like Python, Ruby etc. is missing what make them a useful tool in Haskell.
- exDM69 11y ago> The attempts to introduce monads in other languages like Python, Ruby etc. is missing what make them a useful tool in Haskell. While I agree that the syntactic sugar of the "do" notation in Haskell makes Monads vastly more useful, there are examples where Monads have been applied in other programming languages without any syntactic sugar. For example, there are parser combinator libraries (influenced by Parsec) in many languages. E.g. Python's pyparsec is internally using monads that are defined just as they are in Haskell. Monads are a great idea for many practical tasks in programming, their use in Haskell is often emphasized becuse they're required for IO (which is not the case for imperative languages). For many of the non-IO applications of monads, they're just as useful in other languages too.
- tikhonj 11y agoI've used Async and LWT in OCaml—libraries for monadic asynchronous programming—and the abstraction can still be useful without syntax sugar. Hell, JavaScript promises are basically a bastardized and slightly inconsistent monad, and they're still useful even without syntax sugar. If we could generalize over the API and use them for other things it would be even better, but that's not the JavaScript way.
- olavk 11y agoHow are JS promises monads?
- tikhonj 11y agoThey actually operate on more or less the same principle as Async and LWT, similar to Haskell's Cont. The .then method is bind. Or it would be if they didn't automatically flatten nested promises. Since they do, then is a hybrid of map and bind that doesn't quite cover the use cases for both.