3 ms·
If you're designing a programming language, and you're planning to include monads solely for the sake of IO, the author has a point: Monads are a very complex w
by ekidd 16y ago
If you're designing a programming language, and you're planning to include monads solely for the sake of IO, the author has a point: Monads are a very complex way to perform IO, and you're better off with a simpler abstraction.
But monads are good for dozens of other things, including Bayesian inference[1], computation with optional values, list comprehensions, software transactional memory, quantum mechanics[2] and (to geek out a bit) anything that involves defining a lambda-calculus analog over a topos. Any time your problem domain includes a bunch of hairy matrix math, there may be a lovely, intuitive formulation using monads.
Now, if you're never programmed in Haskell, or if you've stuck to the IO monad, you may not understand why monads are a powerful way to tackle certain kinds of problems. But if you've never used monads in anger, how do you whether or not they're a useful tool?
If you want a relatively programmer-friendly language that supports monads, check out Scala's 'for' loop. It looks like a list comprehension, but it gives you about 90% of what you want from monads in practice.
[1] Here's an article I wrote on probabilistic programming with monads: http://www.randomhacks.net/articles/2007/02/22/bayes-rule-and-drug-tests http://www.randomhacks.net/articles/2007/02/22/bayes-rule-an...
[2] Here's a much cooler article on quantum mechanics with monads: http://blog.sigfpe.com/2007/03/monads-vector-spaces-and-quantum.html http://blog.sigfpe.com/2007/03/monads-vector-spaces-and-quan...
- aristidb 16y agoThere's an often-discussed (hypothetical) extension to Haskell's list comprehensions called Monad comprehensions. I suppose that would be similar to Scala's "'for' loop". But really, the difference between 'do' notation and a syntax based on list comprehensions is not that big. Compare: [(x, y) | x <- [1 .. 10], y <- [1 .. 10]] vs do { x <- [1 .. 10]; y <- [1 .. 10]; return (x,y) } The main difference is that it uses return (which is implicit in the comprehension syntax), and the final element in the do syntax is pushed into the first position in comprehension syntax. (Another alternative would be liftA2 (,) [1 .. 10] [1 .. 10].)