Answered step by step
Verified Expert Solution
Link Copied!

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!image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

More Books

Students also viewed these Databases questions

Question

The "Web" and the Internet are the same thing. a . True b . False

Answered: 1 week ago