Define Eq and Ord instances for Expr and StatementF
Clarification and motivation
This task isn't a completed feature but it's a base for some other features.
I suggest the following semantics for the instances:
- for
Eq Expr
it's pretty obvious - for
Ord Expr
: let's consider an expression less than another one if the height of former one is less the the latter one, in other cases feel free to compare them as you wish (by hash of expr, in lexicographical order, etc). This heights comparison is needed to treat subexpressions of the expression as smaller than the expression. It's needed for CSE optimisation (that hasn't been implemented yet). - for
Eq StatementF
: twoStatementF
have to structurally equal to each other. The trickiest part here is variables that have to be passed somewhere inStatementF
. I suggest having variable counter and allocateCell
-variables whenever we require it. Decrease, when leaving the scope. So, the same procedure is already implemented in a lot of places in the code. The another pitfall is thatStatementF
andIndigoM
mutually recursive, so you have to implementEq
forIndigoM
as well (what is pretty easy if you haveEq
forStatementF
). - for
Ord StatementF
feel free to use whatever semantic that correspondsEq
you want.
Actually, I think it's easier to implement compareExpr :: Expr a -> Expr a -> Int
and compareStatement :: StatementF freer a -> Statements Freer a -> Int
and define Eq
and `Ord via them.
The task might be pretty heavy (in sense of code) so feel free to split it in two MRs.
Acceptance criteria
-
Expr
instances covered with tests -
StatementF
instances covered with tests