Is there a high-level API for doing search-and-replace with regexes in Haskell? In particular, I'm looking at the Text.Regex.TDFA or Text.Regex.Posix packages. I'd really like something of type:

f :: Regex -> (ResultInfo -> m String) -> String -> m String

so, for example, to replace "dog" with "cat" you could write

runIdentity . f "dog" (return . const "cat")    -- :: String -> String

or do more advanced things with the monad, like counting occurrences, etc.

Haskell documentation for this is pretty lacking. Some low-level API notes are here.

Edit
Report