[Haskell-beginners] IO action on a list of [IO a]

Manfred Lotz manfred.lotz at arcor.de
Sat Oct 6 20:38:18 CEST 2012


On Sat, 06 Oct 2012 19:35:13 +0200
"Henk-Jan van Tuyl" <hjgtuyl at chello.nl> wrote:

> On Sat, 06 Oct 2012 16:16:18 +0200, Manfred Lotz
> <manfred.lotz at arcor.de> 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





More information about the Beginners mailing list