[Haskell-cafe] Monad Description For Imperative Programmer
ok
ok at cs.otago.ac.nz
Thu Aug 2 00:04:29 EDT 2007
Someone asked about comparing monads to loops.
If you are chiefly familiar with the i/o and state monads, that doesn't
really make a lot of sense, but there IS a use of monads which IS a kind
of loop.
Only yesterday I was trying to read someone else's Haskell code where
they had imported Control.Monad for the sake of >>= and liftM2. And
how were they using >>= and liftM2?
- they were using >>= on lists, where it means the same as concatMap
To a beginner, I suggest that (concatMap f xs) is clearer than
(xs >>= f)
- they were using (liftM2 f xs ys) on lists, where it means the same
as
[f x y | x <- xs, y <- ys]
No doubt there are people who find the monadic versions clearer.
However, since the monadic operations *ARE* loops when applied to lists,
it could very easily give rise to the misunderstanding that monads have
something to do with looping.
More information about the Haskell-Cafe
mailing list