[Haskell-beginners] Problems with Data types a la carte

Daniel Fischer daniel.is.fischer at web.de
Fri Apr 23 17:35:54 EDT 2010


Am Freitag 23 April 2010 22:52:19 schrieb Rodrigo Geraldo:
> Hi !
>
> I've tried to implement the expression interpreter present in Data types
> a la carte, putting the new "cases" of my data type in a separate
> module. When I'm trying to create a simple
> expression like this:
>
> x :: Expr (Val :+: Add :+: Mult)
> x = (val 2000 `mult` val 399) `plus` (val 3)
>
> I'm getting the following type error that I can't solve:
>

Your problem is the wrong associativity, the type signature is parsed as

Expr ((Val :+: Add) :+: Mult)

while you need

Expr (Val :+: (Add :+: Mult))

Insert the parentheses or add a fixity declaration

infixr k :+:

to Expr.hs (where k must be replaced with an integer from 0 through 9).

>
> Regards
>
> Rodrigo



More information about the Beginners mailing list