[Haskell-cafe] Arithmetic expressions with GADTs: parsing

Roman Cheplyaka 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]
> Hello.
> 
> 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:
> 
> Expr.hs:25:28:
>     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 mailing list