So this is my assignment here in which i have to program the associativity of some expressions, I worked on this a few hours and I'm just missing something obvious. Here are my final two ideas that both somewhat work yet cannot evaluate truly equal expressions properly (The first one gives a parse error) I cannot understand what is wrong. Help :(
data Expr = Const Int | Add Expr Expr deriving Show
instance Num Expr where
fromInteger = Const . fromInteger
(+) = Add
-- I have to write here
instance Eq Expr where
(Const i) == (Const j) = i == j
(Add i j) == (Add a b) = i == a && j == b || i ==b && j == a
(==) (Add e3 (Add e1 e2)) (Add (Add e4 e5) e6) =
(Add(Add e1 e2) e3)==(Add e1 (Add e2 e3))
_ == _ = False