On Fri, 10 Dec 2004, Thomas Johnsson wrote:

> > printastable :: [([Int],Word)] -> String
> >
> > printastable l = concat $ map (\(xs,w) -> (show xs) ++ " " ++ w ++
> > "\n") l
> 
> I'd use
> 
> [ c | (xs,w) <- l, c <- (show xs) ++ " " ++ w ++ "\n" ]
> 
> instead -- after all, list comprehensions provide a much nicer
> syntax for map, filter and concat.

I try to stay away from list comprehension because I can't memorize in
which order the conditions are processed and I have to introduce new
variables. List comprehension means thinking with variables, using 'map'
and 'concat' means thinking with functions.
 Btw. if you want to save characters you can also use 'concatMap':

printAsTable = concatMap (\(xs,w) -> show xs ++ " " ++ w ++ "\n")

or

printAsTable = unlines . map (\(xs,w) -> show xs ++ " " ++ w)

_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to