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=1.1 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id C7938BC69 for ; Thu, 22 Feb 2007 17:57:11 +0100 (CET) Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.232]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1MGvAxk002467 for ; Thu, 22 Feb 2007 17:57:11 +0100 Received: by nz-out-0506.google.com with SMTP id i11so225268nzh for ; Thu, 22 Feb 2007 08:57:09 -0800 (PST) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=UXJIGw55IPHido/49WZlKE8wxb3AEC7A+LWkgx+cgiVMXm9QUn3+/GhLJC1lreyEzrRUehmBeEa45f50tsT+n2q9gxpMKJQ/CwQTOq3S/gQWnq5Y0RS5MONTS7fqj3t5PJR+OyspZAsLgjOH/CG1ZsGl0a+VUJn5aQIFH7/h7Ao= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=XquGJ1uiEsstCowmLF6A1YsOBZtORAueIFLPIjWnjl1Lq1yya2/vkxrcbXqa+gH7+FN36NlT2QCbtCI0c3glDxC0rJ4sTduSHsXKvDnpWfx7gn7P83MhEg/WWZshBuLBfZ5Ee5a3i5Yr8ifHaw+s0KoSINw0dHYML4YrPThmb4s= Received: by 10.65.93.18 with SMTP id v18mr1491518qbl.1172163429255; Thu, 22 Feb 2007 08:57:09 -0800 (PST) Received: by 10.65.98.10 with HTTP; Thu, 22 Feb 2007 08:57:09 -0800 (PST) Message-ID: <9d3ec8300702220857u15e73d6eq8f48066e1a307626@mail.gmail.com> Date: Thu, 22 Feb 2007 17:57:09 +0100 From: "Till Varoquaux" To: "David Teller" , OCaml Subject: Re: [Caml-list] Feature request : Tuples vs. records In-Reply-To: <45DDC424.2020804@ens-lyon.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <45DD6F8C.7080508@ens-lyon.org> <45DD73A8.3040703@fmf.uni-lj.si> <1172148077.5345.18.camel@rosella.wigram> <45DDB697.6080004@ps.uni-sb.de> <9d3ec8300702220757s5c75c7feqee62f051841d1c38@mail.gmail.com> <45DDC424.2020804@ens-lyon.org> X-j-chkmail-Score: MSGID : 45DDCB66.000 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 45DDCB66.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ens-lyon:01 sml:01 fixpoint:01 fixpoints:01 cheers:01 mutable:01 verbose:01 foot:98 martinez:98 polymorphic:01 wrote:01 rec:01 rec:01 caml-list:01 tuples:01 On 2/22/07, David Teller wrote: > Sounds interesting. Do you have documentation on this use of records for > general recursivity ? > > Thanks, > David I really put my foot in my mouth for my previous post (I had just read the part about unlabeled tupple in SML...). Anyway here I come: let rec f a b=3D if false then (*Although this is never called it breaks polymorphisme*) f print_string "a"; a b;; And here is the same using records (and having a more general type): type my_rec=3D{f:'a 'b.('a -> 'b) -> 'a -> 'b};; let rec r=3D{ f=3D(fun a b -> if false then (*Polymorphisme is not b0rken...*) r.f print_string "a"; a b ) };; r.f print_int 5;; This is a very useless example. Thierry Martinez (I know you are reading us) had a cool example and some of the fixpoint operators on: http://okmij.org/ftp/ML/fixpoints.ml use this trick. Cheers, Till > > Till Varoquaux a =E9crit : > > Another simple difference is that you have to declare the type of the > > records whereas types of tupples can be infered. Since the typechecer > > actually uses the type information given, you can use polymorphic > > fields to implement general reccursivity. > > I would also mention row polymorphisme and "mutable" as notable > > differences. You could also note that they are not always > > interchangeable: whilst you wouldn't want to define a new record type > > for every tupple you use (very verbose), direct access to a defined > > field and the "with" keyword (e.g let b=3D{a with x=3D1}) make records > > nice to handle large structures. > > > > Till > >