[Haskell-cafe] Arithmetic expressions with GADTs: parsing

j.romildo at gmail.com j.romildo at gmail.com
Wed May 2 15:08:21 CEST 2012


On Wed, May 02, 2012 at 03:02:46PM +0300, Roman Cheplyaka wrote:
> * j.romildo at gmail.com <j.romildo at gmail.com> [2012-05-02 08:03:45-0300]
[...]
> 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.

You are right in the sense that I cannot mix Expr Bool and Expr Double
in a (O op l r) expression. 

But the parser should be able to parse any form of expressions. So I
rewrite my program to take this into account.

The new versions still does not compile:

Expr.hs:27:23:
    Couldn't match expected type `Double' with actual type `Bool'
    Expected type: ParsecT
                     String () Data.Functor.Identity.Identity (Expr Double)
      Actual type: ParsecT
                     String () Data.Functor.Identity.Identity (Expr Bool)
    In the first argument of `(<|>)', namely `pBool'
    In the second argument of `(<|>)', namely `pBool <|> pEqual'

Romildo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Expr.hs
Type: text/x-haskell
Size: 1398 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120502/ef49cba5/attachment.hs>


More information about the Haskell-Cafe mailing list