[Haskell-cafe] Perl-ish =~ operator

John Meacham john at repetae.net
Mon Feb 23 11:35:59 EST 2004

On Mon, Feb 23, 2004 at 12:09:12PM -0500, Mark Carroll wrote:
> On Tue, 24 Feb 2004 ozone at algorithm.com.au wrote:
> > In my effort to turn Haskell into a language more like Perl
> > (muahaha)[1], I got a bit fed up and implemented something like Perl
> > 5's =~ binding operator (a.k.a. "regex" operator); I thought maybe
> (snip)
> This reminds me that one thing I do miss from the regex stuff I've found
> so far in Haskell is Perl's ? operator for turning greedy matches into
> minimally-short ones. I can still usually do what I need to with Parsec,
> at least, but I just thought I'd mention the issue.

yeah, ? is awesome. of course, if I had my way, I'd go back in time and
make non-greedy matching the default. The silly longest match rule
breaks a lot of the computational niceness of regular expressions.  ah..
em. sorry for the random rant, to get things back on track, I started
writing a Template Haskell module to give one something like perls =~
but it syntax checked the regular expression at compile time and
compiled it to efficient code rather than using the Regex module. so I
didn't have to feel bad about writing /foo/ as I know it will be
compiled to just a simple substring match. perhaps this will inspire
someone to finish the project?

a standard pcre (pcre.org) binding would also be a cool thing to work on. I looked
into writing one, but by default pcre is compiled without utf-8 support
on my system, which made binding to it somewhat useless for my
particular task. however, if we could put a binding in the standard
library, perhaps building a version which works with haskell unicode if
necessary that would be cool. 

John Meacham - California Institute of Technology, Alum. - john at foo.net

More information about the Haskell-Cafe mailing list