[Haskell-cafe] parsing a CSV file

Roman Cheplyaka roma at ro-che.info
Tue May 21 17:06:08 CEST 2013


* Roger Mason <rmason at mun.ca> [2013-05-21 12:22:53-0230]
> Thus far, I have:
> -- derived from RWH
> -- file: ch16/csv2.hs
> import Text.ParserCombinators.Parsec
> 
> headerLines = endBy csvFile endHeader
> csvFile = endBy line eol
> line = sepBy cell (char ',')
> cell = many (noneOf ",\n")
> eol = char '\n'
> 
> parseCSV :: String -> Either ParseError [[String]]
> parseCSV input = parse csvFile "(unknown)" input
> 
> parseHDR :: String -> Either ParseError [[String]]
> parseHDR input = parse headerLines "(unknown)" input
> 
> endHeader = string "Energy Counts"
> 
> This loads into GHCi (7.6.2) OK.  However, when I test it:
> 
> parseHDR "Bruker Nano GmbH Berlin, Germany\nEsprit 1.9\n\nDate:
> 02/05/2013 10:06:49 AM\nReal time: 15000\nEnergy Counts"
> 
> Not in scope: `parseHDR'
> 
> which makes sense because
> 
> ghci> :t endHeader
> 
> <interactive>:1:1: Not in scope: `endHeader'
> 
> Clearly, my naiive implementation of endHeader is no good.

Hi Roger,

"Not in scope" means that that thing is not defined.

So it's not a problem with your implementation, but with the way you
load it.

If you copy-paste your ghci session here, you may get further help.

Roman



More information about the Haskell-Cafe mailing list