Simon Michael | 25 Jan 20:06 2013

why no replace function in our regular expression libs ?

People have put a lot of work into regular expression libraries on
haskell. Yet it seems very few of them provide a replace/substitute
function - just regex-compat and regepr as far as I know. Why is that ?
#haskell says:

<sclv> iirc its because that's a really mutatey operation in the
underlying c libs
<sclv> should be simple enough to write a general purpose wrapper layer
that uses captures to create the effect

Secondly, as of today what do y'all do when you need that functionality
?

-Simon
Clark Gaebel | 25 Jan 20:17 2013
Picon
Picon

Re: why no replace function in our regular expression libs ?

I've needed this recently, too.

End result: I wrote an "Attoparsec.Parser Text", and ran the text through that.

A regex would have been much nicer...

  - Clark


On Fri, Jan 25, 2013 at 2:06 PM, Simon Michael <simon <at> joyful.com> wrote:
People have put a lot of work into regular expression libraries on
haskell. Yet it seems very few of them provide a replace/substitute
function - just regex-compat and regepr as far as I know. Why is that ?
#haskell says:

<sclv> iirc its because that's a really mutatey operation in the
underlying c libs
<sclv> should be simple enough to write a general purpose wrapper layer
that uses captures to create the effect

Secondly, as of today what do y'all do when you need that functionality
?

-Simon

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Albert Y. C. Lai | 26 Jan 00:53 2013
Picon

Re: why no replace function in our regular expression libs ?

On 13-01-25 02:06 PM, Simon Michael wrote:
> People have put a lot of work into regular expression libraries on
> haskell. Yet it seems very few of them provide a replace/substitute
> function - just regex-compat and regepr as far as I know. Why is that ?
[...]
> Secondly, as of today what do y'all do when you need that functionality

I can only speak for myself, why I do not miss regex substitution too much.

Sometimes, regex substitution is exactly the solution, and I use it. But 
the whole job is easily done in a shell script, or even in an editor. So 
I don't use regex substitution in Haskell in this case.

Sometimes, the substitution job is: transform this

   <article>
   <title><code>Monad</code> Tutorial</title>
   <content>...</content>
   </article>

to this

   <!DOCTYPE html etc etc>
   <html>
   <head><title>Monad Tutorial</title></head>
   <body>
     <h1><code>Monad</code> Tutorial</h1>
     ...
   </body>
   </html>

In this job, if a regex solution exists, I don't want to know. I just 
use HXT or XSLT.

Sometimes, regex substitution plus Haskell is exactly the solution. Then 
I use regex-compat. It works. One solution is enough. I don't need a 
hundred choices for regex, or a hundred choices for Int.

Gmane