Reputation: 1
type expr = NUM of int
| PLUS of expr * expr
| MINUS of expr * expr
let rec calc expr1 =
match expr1 with
| NUM i -> NUM i
| PLUS (lexpr1, rexpr1) ->
(match lexpr1, rexpr1 with
| (*(NUM li1,NUM ri1) -> NUM li1+ri1*)
| (lexpr1', rexpr1') -> PLUS (calc lexpr1', calc rexpr1'))
It says
Error: This expression has type expr but an expression was expected of type int
I don't know why errors keep coming out
Upvotes: 0
Views: 58
Reputation:
Ocaml in the line
NUM li1+ri1
first creates a NUM and then tries to add ri1. But since +
operator applies only on int
s and not at expr
and int
, it throws an error.
To fix this add ints first:
NUM (li1+ri1)
Upvotes: 0