Question: problem 1 in ocaml language Library functions: You can use any library functions in the List module for this assignment (please do not use library
problem 1 in ocaml languageLibrary functions: You can use any library functions in the List module for this assignment (please do not use library functions in any other modules). You may find the following functions particularly useful, e.g., List.mapi, List.mem_assoc, and List.assoc. Datatypes: Problems 1-3 are about manipulating tree data structures. In OCaml, you can define a tree data structure using datatype: type 'a tree = Leaf Node of 'a tree * 'a * 'a tree We will assume binary search trees in this assignment and can define a bineary search tree insertion function as the following: let rec insert tree x match tree with Leaf -> Node (Leaf, x, Leaf) Node(1, y, r) -> if x = y then tree else if x insert acc x) Leaf 1 Problem 1 We have seen the benefits of the fold' function for list data structures. In a similar fashion, write a function fold_inorder : ('a -> 'b -> 'a) 'a -> 'b tree That does a inorder fold of the tree. For example, fold_inorder (fun acc x -> acc @[x]) (Node (Node (Leaf, 1, Leaf), 2, Node (Leaf, 3, Leaf))) - 11;2;3] In (): let rec fold_inorder f acc t (YOUR CODE HERE)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
