[Haskell-cafe] Re: wanted: haskell one-liners (in the perl sense of one-liners)

Chris Kuklewicz haskell at list.mightyreason.com
Wed Mar 7 10:29:46 EST 2007


Thomas Hartman wrote:
> Just noticed a comment in
> 
> http://www.serpentine.com/blog/2007/02/27/a-haskell-regular-expression-tutorial/
> 
> 
> which says there's no perl-like regex replace in the library, and links to
> 
> http://hpaste.org/697
> 
> which is an attempt at providing one.
> 
> Not sure if this is useful or not.
> 

Any given replacement routine is less than 10 lines of code and will do exactly
what you need.

A general replacement library has to contend with several things:
  1a) What syntax/semantics?
  1b) How do you supply a specification?  Must it be the same type as the
regular expression or the data?
  1c) How do you report errors?
  2) Which regex-* backends to support?
  3) What types to work on? [Char], Seq Char, ByteString, Lazy ByteString.
  4a) If the backend/type supports lazy matching then does the replacing?
  4b) What if the backend/type does not support lazy match or strictness is desired?
  5) If there is laziness then can it handle infinite streams of input?
  6) Is anyone smart enough to design this API without actual users?

Note that some approaches allow for much more efficiency than others.  Taking a
normal ByteString and performing replacement to create a Lazy ByteString makes
sense, but is a bit of wrinkle.

But as you pointed to on http://hpaste.org/697 any given example of a
replacement routine will be very small, and easy to build on top of the regex-* API.


More information about the Haskell-Cafe mailing list