3 ms·
Wikipedia has a pretty good analogy explanation. I like the idea of monads being "programmable semicolons" which are used to inject side effects between purely
by progman 13y ago
Wikipedia has a pretty good analogy explanation. I like the idea of monads being "programmable semicolons" which are used to inject side effects between purely functional applications.
So if I understand monads correctly then they are basically functions that work like a Unix pipe between functions which takes input data in a monadic container, performs some side effects (I/O for instance), and yields another monadic container with output data that is forwarded to the next function - all that without violating the purely functional character of the whole application chain.
https://en.wikipedia.org/wiki/Monads_in_functional_programming https://en.wikipedia.org/wiki/Monads_in_functional_programmi...
- dllthomas 13y ago"they are basically functions that work like a Unix pipe between functions which takes input data in a monadic container, performs some side effects (I/O for instance), and yields another monadic container with output data that is forwarded to the next function - all that without violating the purely functional character of the whole application chain." That much is true of any applicative functor (which is a superset of monads). The additional power monad gives you is to change up the later portions of that chain based on the earlier results. Of course, a lot of uses of "monads" don't really make the distinction (and applicative functors are plenty useful).
- freyrs3 13y ago> performs some side effects (I/O for instance), What you're describing is the IO monad to first approximation, most monads don't perform side-effects at all ( List, Cont, Maybe, ... ) and the bind operations only performs some pure overloaded operation specific to the monad instance. For example the list monad performs the concatMap function which is pure. instance Monad [] where m >>= f = concat (map f m) return x = [x]