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 discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id BD206BCC9 for ; Sun, 12 Aug 2007 11:12:24 +0200 (CEST) Received: from anchor-post-34.mail.demon.net (anchor-post-34.mail.demon.net [194.217.242.92]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l7C9CO3e019453 for ; Sun, 12 Aug 2007 11:12:24 +0200 Received: from orion.metastack.com ([80.177.38.218]) by anchor-post-34.mail.demon.net with esmtp (Exim 4.42) id 1IK9Um-000Ao0-DA for caml-list@yquem.inria.fr; Sun, 12 Aug 2007 09:12:24 +0000 Received: from countertenor (88-110-115-186.dynamic.dsl.as9105.com [88.110.115.186]) (authenticated bits=0) by orion.metastack.com (8.13.4/8.13.3) with ESMTP id l7C8wTtD027760 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Sun, 12 Aug 2007 09:58:30 +0100 From: "David Allsopp" To: References: <6806cf750708111056v19107705p288e0b0bb152ef63@mail.gmail.com> Subject: RE: [Caml-list] Order of evaluation when constructing record values Date: Sun, 12 Aug 2007 10:12:14 +0100 Organization: MetaStack Solutions Ltd. Message-ID: <015f01c7dcc0$e36fb950$017ca8c0@countertenor> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <6806cf750708111056v19107705p288e0b0bb152ef63@mail.gmail.com> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 Thread-Index: Acfct7nwZCHAzAGTRMmvD+LnTor6cAABSR+A X-Miltered: at discorde with ID 46BECEF8.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 expr:01 unspecified:01 unspecified:01 compiler:01 ints:01 caml-list:01 caml:02 declaration:02 declaration:02 constructing:04 constructing:04 guess:04 inria:06 docs:07 > For this to work, I need the ints to be read in the order given, or I > could end up with a day of 2007 and a year of 11. Is there any > guarantee that OCaml will follow that order of evaluation when > constructing the record? Or do I have to force it with let-bindings > like this: http://caml.inria.fr/pub/docs/manual-ocaml/expr.html - although the Record section doesn't state that the order of evaluation is unspecified, the section on Function application does: I think it's safe to assume that the order of evaluation for record construction is similarly unspecified and so could, in theory, change. > Of course, it's not that big a deal for me to just use the let-binding > method, but I'm curious, and it might make my code look nicer if I can > rely on order of evaluation. Although it looks neat in this instance, in general relying on evaluation order is risky and potentially unclear (which is one of the reasons that the order of evaluation is left unspecified in the language specification). > I seem to have answered my own question by playing around. It appears that > the order of evaluation is last-to-first and based on the order of the > fields in the type declaration, not in the value construction. > Oh well. I guess it's let-bindings for me. Exactly - so here, even a change in the type declaration could have broken your code (even without a compiler change!). See also http://tinyurl.com/ysm8te David