Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedimage text in transcribed

image text in transcribed

image text in transcribedimage text in transcribed

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

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

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

3540416641, 978-3540416647

More Books

Students also viewed these Databases questions

Question

=+free to pirate employees from competitors?

Answered: 1 week ago