3 ms·
They weren't introduced to solve a problem. Monads were definitely introduced to Haskell as a way to solve the problem of I/O -- see Section 7 of http://www.sc
by panic 11y ago
They weren't introduced to solve a problem.
Monads were definitely introduced to Haskell as a way to solve the problem of I/O -- see Section 7 of http://www.scs.stanford.edu/~dbg/readings/haskell-history.pdf http://www.scs.stanford.edu/~dbg/readings/haskell-history.pd... for more details.
It's true that monads existed as a concept in category theory before they were used in programming languages, but they didn't really catch on until their use in Haskell. Certainly you don't see articles about applying other esoteric category theory concepts to Swift programs.
- gohrt 11y agoMonads are generally useful beyond IO, and pure programming style is available (and recommended) in almost every language. From the article you linked: "Although Wadler’s development of Moggi’s ideas was not directed towards the question of input/output, he and others at Glasgow soon realised that monads provided an ideal framework for I/O."
- panic 11y agoYes, definitely. To be clear, I'm a fan (and long-time user) of monads in Haskell, and I think they're a great solution to the problem of embedding impure effects in a pure language. I just don't understand why you'd use them in a language where you can just write the impure effects in a direct style, especially when there's no 'do' notation equivalent.
- Retra 11y agoYou don't usually need them to do IO and state, but they're useful for things like optional and error values. Otherwise, it is mostly pedagogical. Besides, writing things that exist in other languages is useful when you're writing other languages. If you were using C to write a new language with closures (for instance,) you're going to have to implement closures in C. That's a useful exercise, even if nobody is going to use such an inevitably clunky construct in C directly.
- tel 11y agoYou use them precisely when you need a computational/imperative context which differs from the natural ambient one of your language. E.g., Promises in Javascript.