Question: Please code in OCaml language. Given the type tree and the function tree_fold (ignore the map function), code the method function compose using the tree_fold

 Please code in OCaml language. Given the type tree and thefunction tree_fold (ignore the map function), code the method function compose using

the tree_fold function and as told by the description. DO NOT use

Please code in OCaml language.

Given the type tree and the function tree_fold (ignore the map function), code the method function compose using the tree_fold function and as told by the description.

DO NOT use recursion. You can use library functions found in the Stdlib module and the List module, and nothing else other than these two modules.

Thank you.

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 compose tree - Type: (('a ' a ) tree 'a 'a) the in order composition of the nodes. You must implement this function using tree_fold. - Examples: Consider the following diagram of a tree. The rusult of calling compose on this function would be equivalent to ( fun xh(y(f(g(vx))))) let function_tree = Node ( Node(Leaf,(funx>x+1),Leaf))Node(Leaf,(funx>x+xx),Leaf))) \( \begin{aligned} \text { let composed } & =\text { compose function_tree } \\ \text { composed } 0 & =0 \\ \text { composed } 1 & =12 \\ \text { let composed2 } & =\text { compose Leaf } \\ \text { composed2 } 2 & =2 \\ \text { composed2 } 15 & =15\end{aligned} \)

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!