Problems with Data types a la carte

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: src/Main.hs:25:4: No instance for (Add :<: Mult) arising from a use of `plus' at src/Main.hs:25:4-43 Possible fix: add an instance declaration for (Add :<: Mult) In the expression: (val 2000 `mult` val 399) `plus` (val 3) In the definition of `x': x = (val 2000 `mult` val 399) `plus` (val 3) src/Main.hs:25:5: No instance for (Val :<: Mult) arising from a use of `val' at src/Main.hs:25:5-12 Possible fix: add an instance declaration for (Val :<: Mult) In the first argument of `mult', namely `val 2000' In the first argument of `plus', namely `(val 2000 `mult` val 399)' In the expression: (val 2000 `mult` val 399) `plus` (val 3) I've attached the source code... Regards Rodrigo

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
participants (2)
-
Daniel Fischer
-
Rodrigo Geraldo