[Haskell-cafe] Simple Parsec example, question

Peter Schmitz ps.haskell at gmail.com
Wed Sep 15 17:01:34 EDT 2010

Thank you very much for your reply. Adding type sigs did help me think
about it. I got it to work.

I replaced:

> eol = char '\n'
> textLines = endBy eol


> textLine :: Parser String
> textLine = do
>    x <- many (noneOf "\n")
>    char '\n'
>    return x
> textLines :: Parser [String]
> textLines = many textLine

And it can probably be coded more succinctly that that (suggestions welcome).

I wanted to use Parsec because I want to learn it, and just wanted to
start with something very simple.
Thanks again!
-- Peter

On Tue, Sep 14, 2010 at 7:48 PM, Antoine Latter <aslatter at gmail.com> wrote:
> Hi 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,
> Antoine
> [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