Question

I have the following algebraic data types:

data Exp
  = Con Int
  | Var String
  | Op Opkind Exp Exp
  | Input
  deriving (Show,Eq)

data Opkind
  = Plus | Minus | Mult | Div | More | Equal
  deriving (Show,Eq)

That represent expressions in a simple toy language.

However, because I derive Eq, Op Plus (Var "a") (Var "b) is not considered equal to Op Plus (Var "b") (Var "a") even though I would like to treat a+b as an equal expression to b+a.

How do I change (==) for just those instances, without having to specify the behaviour of (==) for all the other instances?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top