From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 4FE90BB91 for ; Mon, 10 Jan 2005 13:16:37 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j0ACGajM028016 for ; Mon, 10 Jan 2005 13:16:36 +0100 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 NAA20931 for ; Mon, 10 Jan 2005 13:16:36 +0100 (MET) Received: from alex.barettalocal.com (h213-255-109-130.albacom.net [213.255.109.130] (may be forged)) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j0ACGZGk005105 for ; Mon, 10 Jan 2005 13:16:36 +0100 Received: from [127.0.0.1] (localhost.localdomain [127.0.0.1]) by alex.barettalocal.com (Postfix) with ESMTP id 9D5BD2BB628; Mon, 10 Jan 2005 13:16:32 +0100 (CET) Message-ID: <41E27220.7040009@barettadeit.com> Date: Mon, 10 Jan 2005 13:16:32 +0100 From: Alex Baretta User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041007 Debian/1.7.3-5 X-Accept-Language: it, en-us, en MIME-Version: 1.0 To: Olivier Andrieu Cc: caml-list@inria.fr Subject: Re: [Caml-list] generic functions References: <41E25116.1010805@barettadeit.com> <20050110.114716.71093554.andrieu@ijm.jussieu.fr> In-Reply-To: <20050110.114716.71093554.andrieu@ijm.jussieu.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Miltered: at concorde with ID 41E27224.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 41E27223.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; baretta:01 caml-list:01 andrieu:01 wrote:01 baretta:01 foo:01 foo:01 rec:01 arbitrarily:01 extensional:01 polymorphism:01 ocaml's:01 variants:01 polymorphic:01 polymorphic:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.0 X-Spam-Level: Olivier Andrieu wrote: > Alex Baretta [Mon, 10 Jan 2005]: > > type poly_int = [ `Int of int ] > > type poly_float = [ `Float of float ] > > > > let foo_int foo = function > > | `Int x -> `Int(x * x) > > | other -> foo other > > > > let foo_float foo = function > > | `Float x -> `Float(x *. x) > > | other -> foo other > > > > let rec foo x = match x with > > | #poly_int -> foo_int foo x > > | #poly_float -> foo_float foo x > > Hum, I would have written this in that way : > ,---- > | let foo_int (`Int x) = `Int (x * x) > | let foo_float (`Float x) = `Float (x *. x) > | > | let foo = function > | | #poly_int as x -> foo_int x > | | #poly_float as x -> foo_float x > `---- > > What's the use for the `other -> foo other' clauses ? In my previous post I mentioned *extensible functions*. The first parameter of single instances of the polymorphic foo (i.e. foo_int and foo_float) allow the generalization of each of these to arbitrarily complex polymorphic type schema. We have exactly 7888 lines of code which contain such late-bound-recursive functions à la foo_int. Obviously it takes a relatively complex example to show why late-bound-recursion is essential to the implementation of a fairly extensional polymorphism with Ocaml's polymorphic variants. Alex -- ********************************************************************* http://www.barettadeit.com/ Baretta DE&IT A division of Baretta SRL tel. +39 02 370 111 55 fax. +39 02 370 111 54 Our technology: The Application System/Xcaml (AS/Xcaml) The FreerP Project