From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA19689; Sat, 11 Sep 2004 11:20:44 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA19810 for ; Sat, 11 Sep 2004 11:20:42 +0200 (MET DST) Received: from fafnir.ens-lsh.fr (fafnir.ens-lsh.fr [193.51.131.254]) by nez-perce.inria.fr (8.13.0/8.13.0) with SMTP id i8B9Kgo9000817 for ; Sat, 11 Sep 2004 11:20:42 +0200 Received: from ([172.16.1.1]) by fafnir.ens-lsh.fr; Sat, 11 Sep 2004 11:20:17 +0200 (CEST) Received: from avalon.ens-lsh.fr (localhost [127.0.0.1]) by avalon.ens-lsh.fr (8.12.8/8.12.8) with ESMTP id i8BAIBse008418 for ; Sat, 11 Sep 2004 11:18:11 +0100 (WEST) Received: from ens-notes1.ens-lsh.fr (ens-notes1.ens-lsh.fr [10.2.1.44]) by avalon.ens-lsh.fr (8.12.8/8.12.8) with ESMTP id i8BAIAib008415; Sat, 11 Sep 2004 11:18:11 +0100 (WEST) Received: from mostha ([10.3.25.17]) by ens-notes1.ens-lsh.fr (Lotus Domino Release 5.0.10) with SMTP id 2004091111203833:4777 ; Sat, 11 Sep 2004 11:20:38 +0200 Date: Sat, 11 Sep 2004 11:21:15 +0200 From: Damien To: skaller@users.sourceforge.net Cc: caml users Subject: Re: [Caml-list] polymorphic variant typing question Message-Id: <20040911112115.11837e15@mostha> In-Reply-To: <1094888964.27775.39.camel@pelican.wigram> References: <1094888964.27775.39.camel@pelican.wigram> Organization: mosthagloups X-Mailer: Sylpheed-Claws 0.9.12 (GTK+ 1.2.10; i386-pc-linux-gnu) Mime-Version: 1.0 X-MIMETrack: Itemize by SMTP Server on ens-notes1/ENS-LSH(Release 5.0.10 |March 22, 2002) at 11/09/2004 11:20:38, Serialize by Router on ens-notes1/ENS-LSH(Release 5.0.10 |March 22, 2002) at 11/09/2004 11:20:39, Serialize complete at 11/09/2004 11:20:39 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Miltered: at nez-perce with ID 4142C36A.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; damien:01 damien:01 ens-lyon:01 caml-list:01 2004:99 combinator:01 compiles:01 recursion:01 recursion:01 overriding:01 jacques:01 wwwfun:01 regexp:01 groups:01 garrigue:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On 11 Sep 2004 17:49:25 +1000 skaller wrote: > Consider this: > [...] > What this does is extend the regular expression > type to allow a group combinator, but then reduce it > by using left/right bracket codes. This typing > compiles. > > Question: how can I replace the last two lines of > the match with something which just handles 'all the > rest of the cases'? > > Do I have to factor the original regexp_t into invariant > and variant parts?? I think yes... I often use the following scheme : << (* invariant type *) type t = [ `A | `B ] (*** first level ***) type 'x v1 = [ t | `C of 'x ] type t1 = 'x v1 as 'x (* open recursion with r *) let r1 r = function | #t as x -> x | `C x -> `C (r x) (* close the recursion for use at the first level *) let rec f1: t1 -> t1 = fun x -> r1 f1 x (*** second level ***) type 'x v2 = [ 'x v1 | `D of 'x ] type t2 = 'x v2 as 'x (* open recursion (use the previous open recursion) *) let r2 r = function (* | `C x -> `D (r x) (* possible overriding of the `C case *) *) | #v1 as x1 -> r1 r x1 | `D x -> `D (r x) (* close the recursion at the second level *) let rec f2: t2 -> t2 = fun x -> r2 f2 x (* second to first level (similar to your groupify function) *) let r21 r = function | #v1 as x1 -> r1 r x1 (* first level recursion *) | `D x -> `C (r x) (* convert GROUPS into brackets here... *) let rec f21: t2 -> t1 = fun x -> r21 f21 x >> You may be interested by this paper from Jacques Garrigue : Hope this helps, damien ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners