Re:Maybe Monads Might Not Matter
by aristidb on Friday February 25, 2011 @11:22AM
(#2262645)
There'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].)
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].)