Effective Haskell: B5.0, Chapter 2, p.51: isBalanced function should consider order of opening / closing parentheses

@RebeccaSkinner
As is, isBalanced would for example consider “Hello)(” as balanced. This can be easily fixed by freezing count at -1 as soon as the count drops below 0 (same for second version on p.52). Maybe there is a more elegant solution. So here is my proposal:

  isBalanced' count s
  | null s = count
  | count < 0 = count
  | ...
1 Like

That’s a great catch. I’ll definitely look at addressing that soon!

1 Like