
10 Mar
2010
10 Mar
'10
6:21 a.m.
From: zaxis
So if the local variable can be changed, then we can use loop, etc. same as imperative languages. For example, for (i=0; i<100; i++) where `i` is a local variable in function.
In addition to John Millikin's suggestion, you can also do: map f [0..99] where f :: Int -> a; f = ... or mapM f [0..99] where f :: Int -> m a; f = ... for monadic actions. Here "f" is the body of the loop. The loop bodies must be completely independent, but this is a very useful technique. Cheers, John