[Haskell-cafe] Parse text difficulty

Jan-Willem Maessen - Sun Labs East Janwillem.Maessen at Sun.COM
Fri Dec 10 11:22:02 EST 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.

Or, if you hate append as much as I do:

[ c | (xs,w) <- l, cs <- [show xs, " ", w, "\n"], c <- cs ]

If you're hard-core, you can turn show into shows and delete a comma...

(OK, it's terribly silly in this example, but I do use list
comprehensions in this way to avoid concat-ing an
already-appended-together list.)

-Jan-Willem Maessen

> -- Thomas
> 
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list