[Haskell-cafe] Simple Parsec example, question
aslatter at gmail.com
Tue Sep 14 22:48:26 EDT 2010
On Tue, Sep 14, 2010 at 8:23 PM, Peter Schmitz <ps.haskell at gmail.com> wrote:
> Simple Parsec example, question
> I am learning Parsec and have been studying some great reference and
> tutorial sites I have found (much thanks to the authors), including:
> I'm having trouble coding a simple parser to count the number of
> lines in a text file.
> "lineCount" fails to compile; the compiler error text is below it.
> Any advice, code, etc. would be appreciated.
> For those using Gtk2Hs + Glade, I have included the glade file after
> the Haskell code, in case you want to try it. (You will need to
> remove the leading "> " and fix some lines that the email wrapped.)
> If you do wish to offer code, feel free to remove or rewrite: eol,
> textLines and lineCount entirely. I'm looking for the simplest
> way to code this.
> Thanks very much,
> -- Peter
What do you expect the type of 'textLines' to be? Does the error
change if you add a type annotation to 'textLines'?
Adding more type signatures is my usual first step in understanding
bewildering error messages.
In this case, I think the issue is that the 'emdBy' function from
Parsec expect two arguments, and you have only give it one. You've
written the 'separator' parser, but you also need to specify what to
parse between the separators.
If this is as complex as the task is, you may be better off with the
function Prelude.lines :-)
More information about the Haskell-Cafe