[Haskell-cafe] parsing a CSV file

Roman Cheplyaka roma at ro-che.info
Tue May 21 19:45:47 CEST 2013


* Roger Mason <rmason at mun.ca> [2013-05-21 13:33:47-0230]
> Hi Roman,
> 
> On 05/21/2013 12:36 PM, Roman Cheplyaka wrote:
> >
> >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
> Starting with a clean ghci session I get this:
> 
> ghci> :l csv.hs
> [1 of 1] Compiling Main             ( csv.hs, interpreted )
> 
> csv.hs:15:24:
>     Couldn't match type `[Char]' with `Char'
>     Expected type: Text.Parsec.Prim.Parsec String () [[String]]
>       Actual type: Text.Parsec.Prim.ParsecT
>                      String () Data.Functor.Identity.Identity [[[[Char]]]]
>     In the first argument of `parse', namely `headerLines'
>     In the expression: parse headerLines "(unknown)" input
>     In an equation for `parseHDR':
>         parseHDR input = parse headerLines "(unknown)" input
> Failed, modules loaded: none.

So this is the real error. If you read it carefully, it says that it
expected [[String]] but got [[[[Char]]]] (i.e. [[[String]]]) as a result
of the headerLines parser.

I don't have time right now to look closer at your code, but I suggest
studying the types of combinators you use (such as endBy) and trying to
write down type signatures for the rest of the values you define.
This way you'll find the error and better understand your program.

A useful trick is to start ghci with -fdefer-type-errors and use ":t" to
inspect types of various expressions that you encounter.

Roman



More information about the Haskell-Cafe mailing list