I have an ocaml function in which I am pattern matching several cases. I keep getting a type error and I can't see how to deal with it. Any help would be appreciated. This is the error message I'm getting : "File "eval.ml", line 40, characters 18-35: Error: This expression has type Env.symEntry". Line 40 is the line with "let l = binding_of env x in"
(* eval_expr: expr -> proc_state -> env -> store -> value *)
(* eval_expr: expr -> proc_state -> env -> store -> int *)
let rec eval_expr (expr:expr) (ps:proc_state) (env:environment) (store:store) : int = match expr with
Add (e1, e2) ->
let r1 = eval_expr e1 ps env store in
let r2 = eval_expr e2 ps env store in
r1 + r2
| Sub (e1, e2) ->
let r1 = eval_expr e1 ps env store in
let r2 = eval_expr e2 ps env store in
r1 - r2
| Mul (e1, e2) ->
let r1 = eval_expr e1 ps env store in
let r2 = eval_expr e2 ps env store in
r1 * r2
| Div (e1, e2) ->
let r1 = eval_expr e1 ps env store in
let r2 = eval_expr e2 ps env store in
r1 / r2
| Neg (e1) ->
let r1 = eval_expr e1 ps env store in
r1 * -1
| IntConst i -> i
(* - variable reads: handle the Id constructor from expr.
use binding_of and
value_at *)
| Id(x) ->
let l = binding_of env x in
let i = value_at store l in i;;
Here is the code for some of the functions and types I used :
module IntMap = Map.Make(struct type t = int let compare = compare end);;
type store = int IntMap.t;;
let value_at store loc = IntMap.find loc store;;
let insert_value store loc v = IntMap.add loc v store;;
let enter_scope env scope = scope::env;;
let exit_scope env = List.tl env;;
let current_scope env = List.hd env;;
type expr = (* Expressions in C-flat *)
(* int operations *)
Add of expr * expr
| Sub of expr * expr
| Mul of expr * expr
| Div of expr * expr
| Neg of expr
(* constants/variables *)
| Id of string
| IntConst of int
(* array/pointer operations *)
| At of expr * expr
| Deref of expr
| AddressOf of expr
(* function *)
| Call of string * expr list
(* pre- & post-increment *)
| Pre of expr
| Post of expr
;;
let binding_of env name =
let lookup name symTab = List.assoc name symTab in
try
lookup name (List.hd env)
with Not_found ->
lookup name (List.hd (List.tl env))
;;