On Nov 23, 2007 6:24 PM, Jules Bean [EMAIL PROTECTED] wrote:
...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
This has terrible endweight. In this imperativesque case, I'd write:
On Fri, 2007-11-23 at 23:01 +0100, Roberto Zunino wrote:
Maurício wrote:
main = mapM_ ((putStrLn ) * putStrLn) $
map show [1,2,3]
Using only standard combinators:
main = mapM_ ((putStrLn ) . putStrLn) $ map show [1,2,3]
== mapM_ ((putStrLn ) . putStrLn . show) [1,2,3]
Maurício wrote:
main = mapM_ ((putStrLn ) * putStrLn) $
map show [1,2,3]
Using only standard combinators:
main = mapM_ ((putStrLn ) . putStrLn) $
map show [1,2,3]
Zun.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
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:
Hi,
If I have two computations a-IO b and
b-IO c, can I join them to get an a-IO
c computation? I imagine something like a
liftM dot operator.
This is called Kleisli composition, by the way; it's
defined as (=) in Control.Monad.
jcc
Even if you didn't know about (=)(...):
main :: IO ()
main = mapM_ ((putStrLn ) * putStrLn) $
map show [1,2,3]
A couple other ways to do this code.
Without monad combinators
main = mapM_ putStrLn . (:) . intersperse . map show $ [1..3]
With your combinator, but collapsing it so we don't map over the
collection