All balanced parentheses for a given N
The code can be sped up, and it can also be simplified. For n &gt; 0, there is a unique way to write a balanced string as (a)b where a and b are balanced strings.

a and b must have n-1 pairs of parentheses, total. This leads us to the following solution:

balancedParens 0 = [""]
balancedParens n = ["(" ++ a ++ ")" ++ b | i &lt;- [0 .. n - 1], a &lt;- balancedParens i, b &lt;- balancedParens (n - i - 1)]