foreach :: (Monad m) => [a] -> (a -> m ()) -> m ()
foreach [] _ = return ()
foreach (x:xs) f = do f x
foreach xs f
> foreach [1..10] (\x ->
> putStrLn (show x)
> )
while :: (Monad m) => m Bool -> m () -> m ()
while cond f = do res <- cond
if res then (f >> (while cond f))
else (return ())
> while (return True) (
> putStrLn "Hello world"
> )