3 ms·
The problem with monads is they are horrible without some form of syntax sugar. I like the metaphor of "programmable semicolon", but in languages without some b
by goto11 7y ago
The problem with monads is they are horrible without some form of syntax sugar. I like the metaphor of "programmable semicolon", but in languages without some built-in support, the "semicolon" becomes repetitive boilerplate which is more code than the actual operations happening in the monad.
- fxj 7y agoI like the "do" notation in Haskell because it boils down the meaning of monads to the following: Monads let you break the functional programming paradigm that a function should have the same value each time it is called. e.g. do { x <- getInput y <- getInput return x+y } here getInput is called two times and each time it has a different value. When you now think about how this can happen in a functional language you have to understand what a monad does. The heureka moment came when I learned about the flatMap in scala which is nothing else but the bind function in haskell ("just flatmap that sXXt") and voila thats how to use monads. See the following explanation: https://medium.com/free-code-camp/demystifying-the-monad-in-scala-cc716bb6f534 https://medium.com/free-code-camp/demystifying-the-monad-in-...