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 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id DF9EABC0A for ; Wed, 4 Apr 2007 03:27:15 +0200 (CEST) Received: from ipmail02.adl2.internode.on.net (ipmail02.adl2.internode.on.net [203.16.214.141]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l341RDOw010564 for ; Wed, 4 Apr 2007 03:27:15 +0200 X-IronPort-AV: E=Sophos;i="4.14,367,1170595800"; d="scan'208";a="105933369" Received: from ppp36-111.lns2.syd6.internode.on.net (HELO [192.168.1.201]) ([59.167.36.111]) by ipmail02.adl2.internode.on.net with ESMTP; 04 Apr 2007 10:57:11 +0930 Subject: Re: [Caml-list] Polymorphic recursion From: skaller To: brogoff Cc: caml-list@yquem.inria.fr, nicolas.pouillard@gmail.com In-Reply-To: References: <6f9f8f4a0704030959l8ebb155g8532e3ee6d31c66d@mail.gmail.com> <9d3ec8300704031035g5a69d98dx7f7e8e5b2f7037f3@mail.gmail.com> Content-Type: text/plain Date: Wed, 04 Apr 2007 11:27:06 +1000 Message-Id: <1175650026.24309.7.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 4612FEF1.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; recursion:01 recursion:01 recursive:01 seq:01 seq:01 recursive:01 polymorphism:01 camlp:01 2007,:98 sourceforge:01 polymorphic:01 polymorphic:01 wrote:01 wrote:01 rec:01 On Tue, 2007-04-03 at 13:00 -0700, brogoff wrote: > On Tue, 3 Apr 2007, Till Varoquaux wrote: > > Therefor, if you wish to use polymorphic recursion (yep you can) you > > might want to use something where you have to specify the type; this > > includes records, objects and recursive modules. So this > > > > type 'a seq = Unit | Seq of ('a * ('a * 'a)seq) > > > > type szRec={f:'a.'a seq -> int};; > > > > let size= > > let rec s = > > {f=function > > | Unit -> 0 > > | Seq(_, b) -> 1 + 2 * s.f b} > > in > > s.f > > > > might be what you where yearning for. > > What I'd be yearning for would be more like > > let rec size : 'a . 'a seq -> int = > fun s -> > match s with Unit -> 0 | Seq(_,b) -> 1 + 2 * (size b) > > rather than having to use recursive modules or higher rank polymorphism > of record fields/polymorphic methods. Why not: let fun rec size : 'a . 'a seq -> int = | Unit -> 0 | Seq(_,b) -> 1 + 2 * (size b) with a nice camlp4 example for people by nicolas.pouillard@gmail.com ? -- John Skaller Felix, successor to C++: http://felix.sf.net