
10 Mar
2009
10 Mar
'09
3:26 p.m.
Hi Andy, Here is a function that parses a comma-separated list of strings:
uncommas :: String -> [String] uncommas s = case break (==',') s of (w,[]) -> [w] (w,_:s') -> w : uncommas s'
We can then sum over the 4th column like this:
main = putStrLn . show . sum . map (read . (!!4) . uncommas) . tail . lines =<< getContents
This program is best read backwards: "getContents" gives stdin as a string and "lines" breaks it into lines. The (!!) function yields the nth element of a list. "read" and "show" convert between strings and integers. Best, Roland