fun parenthesised(text) = parenthesised'(explode(text)) and brackets x list = if list=[] then false else case (hd(list)) of #"{" => curlybraces brackets x (tl(list)) | #"[" => brackets brackets x (tl(list)) | #"(" => parantheses brackets x (tl(list)) | #"]" => x (tl(list) | #")" => false | #"}" => false | _ => brackets x (tl(list) and parenthesised'(list) = if list=[] then true else case (hd(list)) of #"{" => curlybraces parenthesised' (tl(list)) | #"[" => brackets parenthesised' (tl(list)) | #"(" => parantheses parenthesised' (tl(list)) | #"]" => false | #")" => false | #"}" => false | _ => parenthesised'(tl(list)) and parantheses x list = if list=[] then false else case (hd(list)) of #"{" => curlybraces parantheses x (tl(list)) | #"[" => brackets parantheses x (tl(list)) | #"(" => parantheses parantheses x (tl(list)) | #"]" => false | #")" => x(tl(list) | #"}" => false | _ => parantheses x (tl(list)) and curlybraces x list = if list=[] then false else case (hd(list)) of #"{" => curlybraces curlybraces x (tl(list)) | #"[" => brackets curlybraces x (tl(list)) | #"(" => parantheses curlybraces x (tl(list)) | #"]" => false | #")" => false | #"}" => x (tl(list) | _ => curlybraces x (tl(list))