Question: Please code in OCaml language. Given the type tree and the provided function tree_fold (fold_tree), please code the function compose using tree_fold (fold_tree) method with

 Please code in OCaml language. Given the type tree and theprovided function tree_fold (fold_tree), please code the function compose using tree_fold (fold_tree)method with the description provided in the image above. DO NOT use

recursion for this function. You can use helper functions, but do not

Please code in OCaml language.

Given the type tree and the provided function tree_fold (fold_tree), please code the function compose using tree_fold (fold_tree) method with the description provided in the image above. DO NOT use recursion for this function. You can use helper functions, but do not make them recursive.

You can use stdlib module and List module library methods and NOTHING ELSE.

I have provided an example of what the "in order" using a function (you do not need to code the in_order function, that is only an example, if you find it easier to code compose by using in_order then you can code it and use it as a helper as well) in addition to the provided example from compose.

Again, please do not use recursion for compose, and any helpers you make should not be recursive (you can make helper functions, just don't them recursive), and only use these 2 module libraries. If any of these 3 criteria are violated then the answer you provided will be inaccurate and will be given a bad rating.

This is a troublesome code (that's why I'm having problems with it), so thank you if you can help me with it. Please do check to see that your code works by using the examples given above.

type 'a tree = | Node of 'a tree *'a 'a 'a tree Leaf let rec fold_tree fbt= match t with \( \begin{array}{l}\mid \text { Leaf } \\ \mid \text { Node }(l, v, r) ightarrow \text { let res_l }=\text { fold_tree } f b l \text { in } \\ \quad \text { let res_r } r=\text { fold_tree } f b r \text { in } \\ \quad f \text { res_l } v \text { res_r }\end{array} \) in_order tree - Type: ('a tree ' a list) - Description: Using tree_fold, write a function that will return a list containing the in order traversal of the tree. - Examples: let treea = Node(Node(Leaf, 1, Leaf), 2, Node(Leaf, 3, Leaf)) let treeb = Node(Node(Leaf, 1, Leaf), 2, Node(Node(Leaf, 3, Leaf), 4, Leaf)) \( \begin{array}{l}\text { in_order treea }=[1 ; 2 ; 3] \\ \text { in_order treeb }=[1 ; 2 ; 3 ; 4]\end{array} \) 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!