Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please write in OCaml, Thank you! Problem 8 Write a function type 'a tree = Leaf | Node of 'a tree * 'a * 'a
please write in OCaml, Thank you!
Problem 8 Write a function type 'a tree = Leaf | Node of 'a tree * 'a * 'a tree fold_inorder : ('a -> 'b -> 'a) -> 'a -> 'b tree -> 'a That does a inorder fold of the tree. For example, fold_inorder (fun acc x -> acc @ [x]] [] (Node (Node (Leaf, 1, Leaf), 2, Node (Leaf,3,Leaf))) = [1;2;3] In [ ]: type 'a tree = Leaf | Node of 'a tree * 'a * 'a tree let rec fold_inorder f acc t = . (* YOUR CODE HERE *) raise (Failure "Not implemented") In [ ]: assert (fold_inorder (fun acc x -> acc @ [x]) [] (Node (Node (Leaf ,1,Leaf), 2, Node (Leaf,3, Leaf))) = [1;2;3]). Problem 8 Write a function type 'a tree = Leaf | Node of 'a tree * 'a * 'a tree fold_inorder : ('a -> 'b -> 'a) -> 'a -> 'b tree -> 'a That does a inorder fold of the tree. For example, fold_inorder (fun acc x -> acc @ [x]] [] (Node (Node (Leaf, 1, Leaf), 2, Node (Leaf,3,Leaf))) = [1;2;3] In [ ]: type 'a tree = Leaf | Node of 'a tree * 'a * 'a tree let rec fold_inorder f acc t = . (* YOUR CODE HERE *) raise (Failure "Not implemented") In [ ]: assert (fold_inorder (fun acc x -> acc @ [x]) [] (Node (Node (Leaf ,1,Leaf), 2, Node (Leaf,3, Leaf))) = [1;2;3])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