Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
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