[Haskell-cafe] Arithmetic expressions with GADTs: parsing
roma at ro-che.info
Wed May 2 14:02:46 CEST 2012
* j.romildo at gmail.com <j.romildo at gmail.com> [2012-05-02 08:03:45-0300]
> In order to learn GADTs, I have written the attached program, which
> defines a type for arithmetic expressions using GADTs, a parser for
> them, and an evaluation function.
> But my parser does not typecheck. ghc-7.4.1 gives me the error message:
> Couldn't match expected type `Double' with actual type `Bool'
> Expected type: Bool -> Expr Double
> Actual type: Bool -> Expr Bool
> In the first argument of `(<$>)', namely `B'
> In the first argument of `(<|>)', namely `B <$> pBool'
> Any clues on how to fix that?
The alternatives given to <|> must be of the same type. In your case,
one is Expr Double and one is Expr Bool.
Inclusion of pBool in pFactor is probably a mistake — unless you're
going to multiply booleans.
Roman I. Cheplyaka :: http://ro-che.info/
More information about the Haskell-Cafe