From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 8AD71BC0B for ; Thu, 28 Dec 2006 09:07:02 +0100 (CET) Received: from flpvm23.prodigy.net (flpvm23.prodigy.net [207.115.20.53]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id kBS871EC014540 for ; Thu, 28 Dec 2006 09:07:02 +0100 X-ORBL: [67.120.175.91] Received: from [67.120.175.91] (adsl-67-120-175-91.dsl.lsan03.pacbell.net [67.120.175.91]) by flpvm23.prodigy.net (8.13.8 out.dk.spool/8.13.8) with ESMTP id kBS875eG005667; Thu, 28 Dec 2006 00:07:06 -0800 In-Reply-To: References: <20061228.151753.38663586.garrigue@math.nagoya-u.ac.jp> Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Cc: garrigue@math.nagoya-u.ac.jp Content-Transfer-Encoding: 7bit From: Jason Hickey Subject: Re: [Caml-list] Pure visitor patterns Date: Thu, 28 Dec 2006 00:06:54 -0800 To: caml-list@inria.fr X-Mailer: Apple Mail (2.752.3) X-Miltered: at concorde with ID 45937B25.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; recursive:01 recursive:01 quantifiers:01 notation:01 foo:01 foo:01 bool:01 scalable:01 wrote:01 caml-list:01 monomorphic:01 int:01 linear:02 parameters:02 parameters:02 > On 12/27/06, Jacques Garrigue wrote: >> From: Jason Hickey >> >> > Here are my questions: >> > >> > - Why does 'a escape its scope in the recursive definition? >> >> Because during recursive definitions parameters of these definitions >> are handled as monomorphic. So you cannot generalize the 'a locally. Ah, that makes perfect sense. If I understand correctly, the quantifiers in a mutual recursive class definition are hoisted, like this: The definition class type ['a] c1 = ... and ['b] c2 = ... is really more like the following (pardon my notation): ['a, 'b] (class type c1 = ... and c2 = ...) The mistake is to think of it like simple recursive type definitions, like the following (rather useless) definition. type 'a visitor = { visit_foo : 'a -> foo -> 'a; visit_bar : 'a -> bar -> 'a } and foo = { accept : 'a. 'a -> 'a visitor -> 'a; examine : int } and bar = { accept : 'a. 'a -> 'a visitor -> 'a; examine : bool };; I'm not complaining--the fact that you can write any of these types is very cool. >> Another trick to make this pattern more scalable is to use >> constraints >> for parameters. Very good suggestion. This makes it _much_ easier to deal with the multiplicity of types, since the constraints are linear, not quadratic, in the number of cases. Many thanks for your explanation! Jason -- Jason Hickey http://www.cs.caltech.edu/~jyh Caltech Computer Science Tel: 626-395-6568 FAX: 626-792-4257