English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Patterns that evaluate
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-02-14 (22:35)
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#.

"Active patterns" seems to be another name for "simple views" or

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 Jambon