[Haskell-beginners] Compilation error parsing arithmetic expressions with parsec-3.1.2

Antoine Latter aslatter at gmail.com
Wed May 2 06:45:52 CEST 2012


On Tue, May 1, 2012 at 9:38 PM,  <j.romildo at gmail.com> wrote:
> Hello.
>
> I want a parser to parse arithmetic expressions using
> Parsec-3.1.2. Therefore I wrote the attached Haskell module.
>
> But its compilation with ghc-7.4.1 fails with the message:
>
>

Type inference has trouble with parsec sometimes. I gave 'pExpr' a
type signature and it started compiling fine. I picked 'pExpr' to give
the signature to because it was closest to the top of the file - you
can probably pick which one you want to give a signature to.

In my case I went with:

> import Text.Parsec.String

.
.
.

> pExpr :: Parser Expr

but you might want a different signature.

Antoine

> Expr1.hs:22:22:
>    No instance for (Stream s0 m0 Char)
>      arising from a use of `pLexeme'
>    Possible fix: add an instance declaration for (Stream s0 m0 Char)
>    In the second argument of `(<$>)', namely
>      `pLexeme (many1 (satisfy isDigit))'
>    In the expression: read <$> pLexeme (many1 (satisfy isDigit))
>    In an equation for `pNum':
>        pNum = read <$> pLexeme (many1 (satisfy isDigit))
>
>
> Any clues on how to fix this?
>
> Romildo
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



More information about the Beginners mailing list