[Haskell-cafe] Parse text difficulty
iakd0 at clusterf.urz.uni-halle.de
Fri Dec 10 12:43:40 EST 2004
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")
printAsTable = unlines . map (\(xs,w) -> show xs ++ " " ++ w)
More information about the Haskell-Cafe