
6 Oct
2012
6 Oct
'12
6:38 p.m.
On Sat, 06 Oct 2012 19:35:13 +0200
"Henk-Jan van Tuyl"
On Sat, 06 Oct 2012 16:16:18 +0200, Manfred Lotz
wrote: myfor :: (a -> IO () ) -> [IO a] -> IO () myfor _ [] = return () myfor f (x:xs) = do x' <- x f x' myfor f xs
Is there a library function doing just this?
You could use this: import Control.Monad myfor :: (a -> IO () ) -> [IO a] -> IO () myfor f (x:xs) = mapM_ (liftM f) xs
or this: import Data.Functor myfor :: (a -> IO () ) -> [IO a] -> IO () myfor f (x:xs) = mapM_ (f <$>) xs
Shouldn't it be xs instead of (x:xs)? The signatures are the same as in my own myfor. However, when I run my code using your versions of myfor I do not get any output at all. -- Manfred -- Manfred