> module Loop where
> import Data.Char
> for result test step calcResult v
> |test v = for (calcResult result v) test step calcResult (step v)
> |otherwise = result
> fac1 = for 1 (\x-> x>0) (\x->x-1) (*)
> sum1 = for 0 (not.null) tail (\r xs -> r+head xs)
> len1 = for 0 (not.null) tail (\r _ -> r+1)
> rev1 = for [] (not.null) tail (\r xs -> head xs:r)
> for2 result test step calcResult v
> |test v = (for2$!(calcResult result v)) test step calcResult (step v)
> |otherwise = result
> fac3 = for2 1 (\x-> x>0) (\x->x-1) (*)
> fac2 n
> |n<=0 = 1
> |otherwise = n*fac (n-1)
> sum2 [] = 0
> sum2 (x:xs) = x+sum xs
> max2 [x] = x
> max2 (x:xs) = max x (max2 xs)
> fi2 _ [] = []
> fi2 p (x:xs)
> |p x = x:fi2 p xs