[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Martin Jambon <martin.jambon@e...> |
| Subject: | Re: [Caml-list] Patterns that evaluate |
On Tue, 13 Feb 2007, Jon Harrop wrote:
> On Tuesday 13 February 2007 22:04, Jacques Carette wrote:
> > I recently wrote some ocaml code which "worked", but not as I
> > intended... The test cases I tried worked, but I should have tested
> > harder. Apparently I was under the mistaken impression that OCaml's
> > pattern-matching was more "first class"! So I wrote (in part):
> >
> > let buildsimp cast e f1 f2 = fun e1 -> fun e2 -> match (e1,e2) with
> >
> > | ({st = Some e}, _) -> e2
> >
> > and I expected it to work. Only a code review by a colleague 'found'
> > this bug in my code.
> >
> > Question: would it be a difficult extension? This seemed so "natural",
> > I just "used" the feature before it was quite there yet ;-).
>
> F# just introduced active patterns, which does what you want AFAIK. Of course,
> you must disambiguate that from the OCaml's current interpretation of the
> above (binding "e").
That's funny, I posted a syntax extension that does that one week ago,
but I didn't know it was already implemented in F#.
http://caml.inria.fr/pub/ml-archives/caml-list/2007/02/e397c716c448a0aeff92b7af709bb1b4.en.html
http://blogs.msdn.com/dsyme/archive/2006/08/16/ActivePatterns.aspx
"Active patterns" seems to be another name for "simple views" or
vice-versa.
It converged to an extremely similar solution, so it must be a good one
:-)
It doesn't solve the original problem though, which IMHO is better solved
with a standard "when" guard as mentioned earlier.
Martin
--
Martin Jambon
http://martin.jambon.free.fr