Question: OCAML (see image) (* write a fubction that checks that parenthisis are balnaced: Parenthisis are balenced if there are no parenthises Parenthisis are balenced if

OCAML (see image) OCAML (see image) (* write a fubction that checks that parenthisis are(*

write a fubction that checks that parenthisis are balnaced:

Parenthisis are balenced if there are no parenthises

Parenthisis are balenced if ( and ) enclose a balenced parenthises

Parenthisis are balenced if balenced parenthises are ajacent to a balenced parenthisis

For example,

matching_parens "" = true

matching_parens "((((((((((()))))))))))" = true

matching_parens "()()()()()()" = true

matching_parens "(()())" = true

matching_parens "())(()" = false

*)

(* 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 | :: 1 -> res. [1] ((char list) option) matching parens_prefix : (char list) -> ((char list) option) the and keyword allows mutual recursion let rec matching_paren_prefix (s: char list) : ((char list) option) = failwith "unimplemented" and matching_parens_prefix (ls: char list) : ((char list) option) = failwith "unimplemented" such that matching paren_prefix [] = None matching paren_prefix (explode "(???") = None matching_paren_prefix (explode "(???") = Some ['?'; '?'; '?'] matching_paren_prefix (explode "(((())))123") = Some ['1'; '2'; '3'] matching_paren_prefix (explode "000") = Some ('(';')'; '('; ')'] matching_paren_prefix (explode "(000) abc") = Some ['a'; 'b'; 'c'] matching parens_prefix [] = Some [] matching parens_prefix (explode "000") = Some [] matching_parens_prefix (explode "aa") = Some [')'; 'a'; 'a'] let rec matching_parens (tree: string) : bool - 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!