title: replacement / substition with Haskell regex libraries
body: <p>Is there a high-level API for doing search-and-replace with regexes in Haskell? In particular, I'm looking at the <code>Text.Regex.TDFA</code> or <code>Text.Regex.Posix</code> packages. I'd really like something of type:</p>
  
  <pre><code>f :: Regex -&gt; (ResultInfo -&gt; m String) -&gt; String -&gt; m String
  </code></pre>
  
  <p>so, for example, to replace "dog" with "cat" you could write</p>
  
  <pre><code>runIdentity . f "dog" (return . const "cat")    -- :: String -&gt; String
  </code></pre>
  
  <p>or do more advanced things with the monad, like counting occurrences, etc.</p>
  
  <p>Haskell documentation for this is pretty lacking. Some low-level API notes are <a href="http://www.serpentine.com/blog/2007/02/27/a-haskell-regular-expression-tutorial/" rel="noreferrer">here</a>.</p>