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