Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

F Sharp programming Also given the following: type env = (string * int) list let

ID: 3749865 • Letter: F

Question

F Sharp programming

Also given the following:

type env = (string * int) list

let rec lookup (env: env) x =
match env with
| (y, v) :: r -> if x = y then v else lookup r x
| [] -> failwith (x + " not found")

In this problem we will consider a variation of the datatype expr where we represent operators with an enumeration type instead of the string type and we add support for variables, to represent arithmetic expressions with variables type oper Neg Not type oper2 Add Mul Sub Less Eq And type aexpr I C of int I V of string l Op1 of operaexpr l Op2 of oper2aexpr aexpr With the two datatypes above, an expression like - (+3), say, is represented as Op2 (Mul, op1(Neg, Var "x"), (Add , Var "y", c 3) ) . Similarly, an expression like (

Explanation / Answer

It's Clearly given that,

e1 = v-(w+z)

e2 = 2*(v-4*w-z)

e3 = x+y+z+v

are of type aepr

Hence the required F# variable is expressed as

e1 = Op2(Sub,Var "v",Op2(Add,Var "w" ,Var "z"))

e2 = Op2(Mul,C 2,Op2(Mul,Op2(Sub,Var "v",C 4),Op2(Sub,Var "w",Var "z")

e3 = Op2(Add,Var "x",Op2(Add,Var "y",Op2(Add,Var "z",Var "v")))