Checking if a string consists of balanced parenthesis

后端 未结 4 2312
渐次进展
渐次进展 2021-02-20 04:01

I wrote the following program to check strings for balanced parenthesis:

isBalanced xs = isBalanced\' xs []

isBalanced\' [] [] = True
isBalanced\' [] _  = False         


        
4条回答
  •  無奈伤痛
    2021-02-20 04:37

    Probably overkill for a problem this simple, but you could try looking up parser combinators.

    As a more elementary simplification, you could rewrite your recursion into folding over a function that takes a stack and a character from the string to a new stack. (Whether this would make actually it simpler is in the eye of the beholder, though).

提交回复
热议问题