[Haskell-cafe] Simple Parsec example, question
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.
> 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.
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, 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 :-)
> Take care,
>  http://hackage.haskell.org/packages/archive/parsec/3.1.0/doc/html/Text-Parsec-Combinator.html#v:endBy
>  http://haskell.org/ghc/docs/6.12.1/html/libraries/base-184.108.40.206/Prelude.html#v:lines
More information about the Haskell-Cafe