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.5 required=5.0 tests=AWL,RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_SORBS_WEB autolearn=disabled version=3.1.3 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id A06D4BB84 for ; Thu, 14 Aug 2008 12:23:36 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmUBAKCko0jC2fJbo2dsb2JhbACJNIhIAQEBAQEBBwUIBxGkB4FV X-IronPort-AV: E=Sophos;i="4.32,208,1217800800"; d="scan'208";a="16111887" Received: from anchor-post-33.mail.demon.net ([194.217.242.91]) by mail1-smtp-roc.national.inria.fr with ESMTP; 14 Aug 2008 12:23:36 +0200 Received: from orion.metastack.com ([80.177.38.218]) by anchor-post-33.mail.demon.net with esmtp (Exim 4.67) id 1KTZzN-0001hT-AT for caml-list@yquem.inria.fr; Thu, 14 Aug 2008 10:23:35 +0000 Received: from orion.metastack.com (IDENT:25@localhost [127.0.0.1]) by orion.metastack.com (8.13.4/8.13.3) with ESMTP id m7EA4OJK018893 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 14 Aug 2008 11:04:24 +0100 Received: (from defang@localhost) by orion.metastack.com (8.13.4/8.13.3/Submit) id m7E9rHOq018877 for ; Thu, 14 Aug 2008 10:53:17 +0100 X-Authentication-Warning: orion.metastack.com: defang set sender to using -f Received: from countertenor ([149.254.192.192]) by orion.metastack.com (envelope-sender ) (MIMEDefang) with ESMTP id m7E9rERb018875; Thu, 14 Aug 2008 10:53:17 +0100 (BST) From: "David Allsopp" To: "'Brighten Godfrey'" , "'Edgar Friendly'" Cc: "'OCaml List'" References: <200808102038.40534.jon@ffconsultancy.com><48A226E3.5050500@gmail.com><735BE8E5-2CCB-41FA-87E7-8E4027966048@cs.berkeley.edu><48A2D834.5020508@gmail.com> <746B9595-EA63-4E8F-8994-DF815F71D078@cs.berkeley.edu> Subject: RE: [Caml-list] Record field label locality Date: Thu, 14 Aug 2008 11:11:55 +0100 Organization: MetaStack Solutions Ltd. Message-ID: <55ED4D00B9044B45A915918B27CC4A35@countertenor> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 Thread-Index: Acj96gNSU4aldgeGRBK6TFQsf/SIWgACnbsw X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512 In-Reply-To: <746B9595-EA63-4E8F-8994-DF815F71D078@cs.berkeley.edu> X-Scanned-By: MIMEDefang 2.63 on 80.177.38.218 X-Spam: no; 0.00; locality:01 ocaml:01 ocaml:01 typing:01 caml-list:01 declaring:02 linking:02 let:03 let:03 representing:05 representing:05 i'd:06 manual:06 explanation:06 label:07 > This is a good point. Thanks for the explanation. I'm having a hard > time thinking of any case other than =,<,> etc where type information > would be necessary to determine code generation. On the other hand > if you break the separation for those operators, maybe it's OK to > break it for record names as well. Until OCaml knows the type of the record, field access can't happen either - because OCaml doesn't know how to map the field name to a field number within the block representing the value (I'd highly recommend reading Section 18.2 of the manual - even if you never plan on linking C code, it gives a good insight into how the OCaml code you write deals with values). Edgar's point is that after type-checking you throw away all of the type inferences. So when generating the code, the code generator sees [x.f1] again and has no idea what type the field [f1] comes from - with x.M2.f1 it knows to look at the *declared* type [M2.t] and so discovers that the field named [f1] will be stored in field 1 of the block representing the value. > > Also you lose the compositionality as before - you can't break this > > function into two parts because the second line "needs" the first line > > to work. > > It can still work, for example this would work: > > let garlic_part_1 () = {M2.f2=5; M2.f1="garlic"} > let garlic_part_2 x = x.f1 > > let return_garlic () = > garlic_part_2 (garlic_part_1 ()) A brief aside (but I think relevant given your complaint!) - you only have to name one of the fields fully when declaring a record - so your first line can be: let garlic_part_1 () = {M2.f2=5; f1="garlic"} which does save a little typing! David