[Haskell-cafe] Re: Composing monads
Jules Bean
jules at jellybean.co.uk
Fri Nov 23 13:24:03 EST 2007
> module Main (Main.main) where
> import Control.Monad
> import System.IO
>
> (>*>) :: Monad m => m () -> (a -> m ()) -> (a -> m ())
> (>*>) f f' = \a -> do{
> f;
> f' a;
> }
>
> main :: IO ()
> main = mapM_ ((putStrLn "") >*> putStrLn) $
> map show [1,2,3]
There is nothing wrong with that, but I would normally write:
mapM_ (\a -> putStrLn "" >> putStrLn a) $ map show [1,2,3]
...i.e. I wouldn't be afraid of a lambda in a case like that. IME it's
moderately common to have to do:
mapM_ (\a -> some stuff >> something_with a >> some stuff) ll
Jules
More information about the Haskell-Cafe
mailing list