3 ms·
If you get to around lecture 9, a classic example I always tell people to start with is a calculator! For instance, here's the SML code for it: ``` datatype e
by brandonspark 3y ago
If you get to around lecture 9, a classic example I always tell people to start with is a calculator!
For instance, here's the SML code for it:
```
datatype exp =
Num of int
| Plus of exp * exp
| Minus of exp * exp
| Times of exp * exp
| Div of exp * exp
```
Implement the function `eval : exp -> int`, which evaluates the expression as best as it can. Assume no division by zero.
Extra credit: Can you implement `eval' : exp -> int option`, that returns `SOME n` if the expression evaluates, and `NONE` if it divides by zero?