datatype mixed_expression =
ME_NUM of int
| ME_PLUS of mixed_expression * mixed_expression
| ME_TIMES of mixed_expression * mixed_expression
| ME_LESSTHAN of mixed_expression * mixed_expression;
datatype value =
INT_VAL of int
| BOOL_VAL of bool
| ERROR_VAL;
I am given these data types and this is my approach
fun eval e =
case e of
ME_NUM x => INT_VAL x
| ME_PLUS (l, r) => eval l + eval r
I got the following error message.
**Error: overloaded variable not defined at type
symbol: +
type: value**
I have no clues on how to solve these issues since I am not allowed to use mutation.
The error message tells you what you need to know. When you write:
The expressions
eval landeval ryield typevalue. There is no+operator for this type.As a style note, your
caseis extraneous in this situation.You should also get a warning about pattern-matching being non-exhaustive as you haven't handled
ME_TIMESorME_LESSTHAN.Really, what you need to do is define a function which can add two
valuevalues.There are lots of combinations you'll need to pattern-match on. You may want to just define a function that coerces a
valueinto anint.Then you could write something like: