Question: Please code in OCaml language. Given the type tree, please code the functions: tree_init, split, and from_pre_in . You can use recursion along with, and

 Please code in OCaml language. Given the type tree, please codethe functions: tree_init, split, and from_pre_in. You can use recursion along with,

and only with library functions found in the Stdlib module and the

List module. If it's helpful, I have also provided a tree_fold andmap function in the image above that can be used as helpers.

Please code in OCaml language.

Given the type tree, please code the functions: tree_init, split, and from_pre_in. You can use recursion along with, and only with library functions found in the Stdlib module and the List module.

If it's helpful, I have also provided a tree_fold and map function in the image above that can be used as helpers.

Thank you.

type 'a t= 'a option = None I Some of ' a type 'a tree = | Node of 'a tree *'a 'a 'a tree Leaf let tree_fold f init tree = let rec aux = function Leaf init | Node (l,v,r)f(auxl)v( aux r) in aux tree let map tree f= let f facc lr= Node (l,fx,r) in tree_fold f facc Leaf tree tree_init fv - Type: ('a ( ( a+b ' a ) option) ' a 'b tree) - Description: A generator f is a function that returns 3 values: v1,v2,v3. Using the definition of type option, f and an init value v, build a tree that has a root node with value v2 and a new generated left subtree with init value v1 and a new generated right subtree with init v3. If f returns None, a Leaf will be placed into the tree. - Examples: let generator 1a= if a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!