[Haskell-cafe] foreach
Tim Newsham
newsham at lava.net
Wed Sep 13 00:00:31 EDT 2006
I was rewriting some non-haskell code in haskell and came up with this
construct:
foreach l f = mapM_ f l
main = do
args <- getArgs
foreach args (\arg -> do
foreach [1..3] (\n -> do
putStrLn ((show n) ++ ") " ++ arg)
)
)
which is reminiscent of foreach in other languages. Seems fairly
useful and I was wondering how hard it would be to add some syntactic
sugar to the "do" construct to make it a little prettier (ie.
not require the parenthesis, binding and nested do, as:
main = do
args <- getArgs
foreach args arg
foreach [1..3] n
putStrLn ((show n) ++ ") " ++ arg)
would this type of transformation be possible with template haskell
or does this need stronger support from the parser to pull off?
Tim Newsham
http://www.thenewsh.com/~newsham/
More information about the Haskell-Cafe
mailing list