I experienced a following problem while dealing with some text processing.<br><br>I have a text and want to get the same text with parts enclosed into {} or [] stripped away. Substituting them with a &#39; &#39; would also work.<br>


<br>Here is the code I wrote (T is Data.Text):<br><br><span style="font-family: courier new,monospace;">stripBrackets :: T.Text -&gt; T.Text</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">stripBrackets text = snd $ T.mapAccumL f 0 text where</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">    f depth c = let </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        depth&#39; = depth + d&#39; c</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">        c&#39; | depth &gt; 0 || depth&#39; &gt; 0 = &#39; &#39; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">           | otherwise = c </span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">        in  </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        (depth&#39;, c&#39;) </span><br style="font-family: courier new,monospace;">


<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    d&#39; &#39;{&#39; = 1 </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    d&#39; &#39;[&#39; = 1 </span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">    d&#39; &#39;}&#39; = -1</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    d&#39; &#39;]&#39; = -1</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">    d&#39; _   = 0 </span><br><br>The only problem is that it takes about a minute to complete on 3GHz+ processor when text is a 30k chars long.<br><br>Any ideas how to improve this code?<br>


<br>--<br>Regards, Petr<br><br>