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.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE 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 BC277BC69 for ; Fri, 23 Feb 2007 02:40:04 +0100 (CET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1N1e2Ce013482 for ; Fri, 23 Feb 2007 02:40:03 +0100 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.7/8.13.7) with ESMTP id l1N1dqCD020147; Fri, 23 Feb 2007 10:39:53 +0900 (JST) Date: Fri, 23 Feb 2007 10:39:45 +0900 (JST) Message-Id: <20070223.103945.99613677.garrigue@math.nagoya-u.ac.jp> To: David.Teller@ens-lyon.org Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Feature request : Tuples vs. records From: Jacques Garrigue In-Reply-To: <45DDC1CB.2090401@ens-lyon.org> References: <7639252.205431172158497978.JavaMail.www@wwinf2216> <45DDC1CB.2090401@ens-lyon.org> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Miltered: at concorde with ID 45DE45F2.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ens-lyon:01 gava:01 unboxed:01 arrays:01 arrays:01 unboxing:01 mutable:01 polymorphism:01 ocaml:01 variants:01 syntax:01 sml:01 syntax:01 struct:01 cheers:01 From: David Teller > Frederic GAVA a =E9crit : > > Another difference is that (If I remember) record of float are > > unboxed and not tuple of float. But perhaps it could be done. > > = > I assume that's not a real difficulty. I might be wrong. Not theoretically difficult, since it is already done for float arrays, but there could be a severe performance hit: since a tuple can be created inside a polymorphic function, one would need to check all components to see whether they are floats or not. (The situation is better with float arrays: one only needs to check the first component, since all the others are bound to have the same type.) So I would say that unboxing tuples of floats would not be worth it. More generally, one has much more freedom for using clever representations when using nominal (declared) types than when using structural ones. This also includes the use of embedded mutable fields, for instance. Another advantage of nominal typing is that the intended types become explicit. This way you can immedietely see how a value is supposed to be used. This also gets you early error message for missing fields when= you change a type definition. So nominal typing has some advantages both in terms of efficiency and detection of errors, the second advantage being particularly helpful for beginners. On the other hand structural typing avoids extra definitions, and allows more code sharing and polymorphism. One cannot imagine ML without structural tuples. In ocaml, you have also objects that can mimic records, and polymorphic variants for sum types. > I'm more concerned about having to > * declare every record type I use -- that looks to me clumsy and Java= -like See above for one rationale. > * differenciate between records and tuples during pattern-matching Hard to avoid when one type is structural and the other nominal. > * having to learn/teach two different implementations of what is = > essentially the same concept Again, they have both the same set-theoretic interpretation, but the distinction nominal/structural is fundamental at the type level. I agree with you that this will be hard to explain this to beginners. > * having to learn/teach that third meaning of operator =3D (the first= one = > being comparison between values and the second one being its use in l= et = > x =3D ...). Ah, syntax... Unfortunately, it is as it is, and this from the beginning of ML. Even SML shares the same syntax. If you want a far fetched a posteriori explanation: a record is basically the same thing as a first class module with only value components. Field access uses the same syntax. So you can see {x =3D 3; y =3D 5} as a shorthand for = struct let x =3D 3 let y =3D 5 end See the "=3D" in both? Of course this does not explain other differences between records and modules... Cheers, Jacques Garrigue