[Haskell-cafe] Irrefutable pattern love and new regex engine.
knomenet at gmail.com
Tue Jan 22 14:32:05 EST 2008
On Jan 22, 2008 11:59 AM, Derek Elkins <derek.a.elkins at gmail.com> wrote:
> On Tue, 2008-01-22 at 11:55 -0500, Michael Speer wrote:
> > I've been using the creation of a regular expression engine as an
> > ongoing project to learn Haskell. Last night I created the newest
> > iteration.
> > My love for the irrefutable pattern can be found in the definition of
> > the rexn ( apply repetition to extracted nodes ) function below.
> > /snip
> > rexn ns pps = let ( ~( xs , rps ) ,
> > ~( ~( nxs ) ,
> > ~( rxs , rrps ) ) ) = ( exn nxs pps ,
> ~nxs is redundant.
> > Beautiful, beautiful lazy execution and irrefutable pattern matching.
> > The data flow is able to easily twist in and out of functions, even as
> > an argument to the function call that creates it.
> > Is this kind of usage normal?
> No. Irrefutable patterns are usually the right thing to use in circular
> programs, but usually you only need a few well-placed irrefutable
> patterns. I suspect most (all?) of yours are unnecessary. The use of
You're absolutely right. Thank you. I am learning this on my own and
had originally figured out how to use them by nesting like that. I
had written something like this without them and got it to work on
discovering and adding them. Not one of the lazy marks was required
in the current version. The implicit lazy bindings carried everything
through fine. Perhaps it was the nested tuples that required them in
the other version. It would smash the stack without them.
> tuples also feels a bit excessive as an impression. I'd have to really
> look to decide, but it gives me the feeling that a data structure should
> be being used somewhere. Your many unnecessary parentheses bothers me,
> but I tend to dislike any unnecessary ones except where there might
> reasonably be some ambiguity while reading. I also recommend trying a
> different way of laying out your code as most of it is wrapped below and
> most of -that- is due to it being excessively indented. Perhaps pull
> some of the lambdas into functions.
I didn't consider the wrapping when I posted. It is easier read where
I posted it in my blog :
More information about the Haskell-Cafe