[Haskell-cafe] Simple Parsec example, question

Antoine Latter aslatter at gmail.com
Tue Sep 14 22:48:26 EDT 2010

Hi Peter,

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:
> http://legacy.cs.uu.nl/daan/download/parsec/parsec.html#UserGuide
> http://legacy.cs.uu.nl/daan/download/parsec/parsec.html#ReferenceGuide
> http://book.realworldhaskell.org/read/using-parsec.html
> http://lstephen.wordpress.com/2007/06/19/first-go-with-parsec/
> http://jonathan.tang.name/files/scheme_in_48/tutorial/overview.html
> http://www.defmacro.org/ramblings/lisp-in-haskell.html
> 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[1], 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[2] :-)

Take care,

[1] http://hackage.haskell.org/packages/archive/parsec/3.1.0/doc/html/Text-Parsec-Combinator.html#v:endBy

[2] http://haskell.org/ghc/docs/6.12.1/html/libraries/base-

More information about the Haskell-Cafe mailing list