Question: Ocaml! (* TODO: write a fubction that reads bool trees : for all (finite) t : bool trees. read_bool_tree t = Some (show_bool_tree t) For

Ocaml! (*

TODO: write a fubction that reads bool trees :

for all (finite) t : bool trees.

read_bool_tree t = Some (show_bool_tree t)

For example,

read_bool_tree "true" = Some (Leaf true)

read_bool_tree "false" = Some (Leaf false)

read_bool_tree "tralse" = None

read_bool_tree "(true^false)" = Some (Node (Leaf true, Leaf false))

read_bool_tree "((true^(true^false))^((true^(true^false))^false))" =

Some

(Node (Node (Leaf true, Node (Leaf true, Leaf false)),

Node (Node (Leaf true, Node (Leaf true, Leaf false)), Leaf false)))

*)Ocaml! (* TODO: write a fubction that reads bool trees : for

(* the type of a plymorphic tree *) type 'a tree - | Leaf of 'a Node of 'a tree * 'a tree (* standard functions to convert between strin and char list *) let explode s = let rec exp i l = if i res | C :: 1 -> res. [i] ((bool * (char list)) option) such that read_bool_prefix (explode "true???") = Some (true, ['?'; '?'; '?']) read_bool_prefix (explode "false123") = Some (false, ['1'; '2'; '3']) read_bool_prefix (explode "antythingales") = None read_bool_prefix [] = None write a helper function read_bool_tree_prefix (char list) -> ((bool tree * (char list)) option) such that read_bool_tree_prefix [] = None read_bool_tree_prefix (explode "true???") = Some (Leaf true, ['?'; '?'; '?'1) read_bool_tree_prefix (explode "(true false) 124") Some (Node (Leaf true, Leaf false), ['1'; '2'; '4']). read_bool_tree_prefix (explode "(true"(true false))aaa") = Some (Node (Leaf true, Node (Leaf true, Leaf false)), ['a'; 'a'; 'a']). read_bool_tree_prefix (explode "(true^(truefa se)) aaa") = None let rec read_bool_tree (tree: string) : ((bool tree) option) = failwith "unimplemented

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!