Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(* let rec add_b a b = if a = 0 then b else add_b (dec a) (inc b) Desugar this to: let rec add_b
(* let rec add_b a b = if a = 0 then b else add_b (dec a) (inc b) Desugar this to: let rec add_b = fun a b -> if a = 0 then b else add_b (dec a) (inc b) Bind the name "add_b" to the value: fun a b -> if a = 0 then b else add_b (dec a) (inc b) Evaluate (add_b 2 5) apply (fun a b -> if ...) to 2, 5 substitute 2 for a, 5 for b in (if ...) -> if 2 = 0 then 5 else add_b (dec 2) (inc 5) evaluate (if 2 = 0 then 5 else add_b (dec 2) (inc 5)) if is a special form, so evaluate the first operand: evaluate (2 = 0) apply = to 2, 0 -> false first argument of if is false, so evaluate the third operand: evaluate (add_b (dec 2) (inc 5)) evaluate (dec 2) apply dec to 2 -> 1 evaluate (inc 5) apply inc to 5 -> 6 apply (fun a b -> if ...) to 1, 6 substitute 1 for a, 6 for b in (if ...) -> if 1 = 0 then 6 else add_b (dec 1) (inc 6) evaluate (if 1 = 0 then 6 else add_b (dec 1) (inc 6)) if is a special form, so evaluate the first operand: evaluate (1 = 0) apply = to 1, 0 -> false first argument of if is false, so evaluate the third operand: evaluate (add_b (dec 1) (inc 6)) evaluate (dec 1) apply dec to 1 -> 0 evaluate (inc 6) apply inc to 6 -> 7 apply (fun a b -> if ...) to 0, 7 substitute 0 for a, 7 for b in (if ...) -> if 0 = 0 then 7 else add_b (dec 0) (inc 7) evaluate (if 0 = 0 then 7 else add_b (dec 0) (inc 7)) if is a special form, so evaluate the first operand: evaluate (0 = 0) apply = to 0, 0 -> true first argument of if is true, so evaluate the second operand: result: 7 *)
Please help solve this (by adding the missing lines and modifying the instructions in OCaml functional programming language asap thanks!!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started