Whenever I read about Monad example, they always present IO as a case study.
Are there any examples of monads doing list manipulation which somebody could present? I apr
Here is a very stupid way to find pairs of divisors for a given integer:
divisors:: Int -> [(Int,Int)]
divisors n = do
x <- [1 .. n]
y <- [1 .. n]
if x*y == n then return (x, y) else []
The meaning of this fragment ought to be fairly straight-forward. Obviously, this is a stupid way to solve this specific problem. (There are far more efficient methods possible in this case.) But now imagine some more complicated problem, where this search is very complex. This kind of idiom for searching can be quite useful.