From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 212FBBDDA for ; Fri, 26 Aug 2005 19:00:24 +0200 (CEST) Received: from smtp.cegetel.net (mf00.sitadelle.com [212.94.174.67]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j7QH0NNb004195 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Fri, 26 Aug 2005 19:00:23 +0200 Received: from [192.168.144.2] (84-4-33-159.adslgp.cegetel.net [84.4.33.159]) by smtp.cegetel.net (Postfix) with ESMTP id 9C21B1A4398; Fri, 26 Aug 2005 19:00:22 +0200 (CEST) Message-ID: <430F4AA5.5000803@univ-savoie.fr> Date: Fri, 26 Aug 2005 19:00:21 +0200 From: Christophe Raffalli User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716) X-Accept-Language: fr, en MIME-Version: 1.0 To: Ville-Pertti Keinonen Cc: Jon Harrop , caml-list@yquem.inria.fr Subject: Re: [Caml-list] Re: Parameter evaluation order References: <43065B83.6050503@dravanet.hu> <430CE193.9000805@univ-savoie.fr> <430EE6A1.9040705@univ-savoie.fr> <200508261110.41183.jon@ffconsultancy.com> <430F0669.6050103@univ-savoie.fr> <430F0CCF.3030103@exomi.com> In-Reply-To: <430F0CCF.3030103@exomi.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Miltered: at nez-perce with ID 430F4AA7.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; christophe:01 raffalli:01 christophe:01 raffalli:01 univ-savoie:01 caml-list:01 semicolons:01 ocaml's:01 grammar:01 ocaml:01 recursive:01 vals:01 allocates:01 heap:01 variants:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 Ville-Pertti Keinonen a écrit : > Christophe Raffalli wrote: > >> Jon Harrop a écrit : > > > >>> Semicolons are used in many places in OCaml's grammar. Would you expect the members of a list literal to be evaluated left-to-right, for example? > > > >> yes I would ... > > > > An OCaml list is built starting with the tail. Left-to-right evaluation could end up using huge amounts of temporaries. > This is the same problem as the problem of a tail recursive map function, which is important and has reasonable solution. the only risk is to charge the grey vals list of the GC if the evaluation of the list elements allocates enough memory to move partially constructed cons cell to the major heap. But yet I quite agree this is a good point ... but you just need to redefine list as type 'a rlist = Cons of 'a rlist * 'a | Nil ;-) anyway one of the data type list or rlist as an efficiency problem whatever evaluation order you choose. May be the good evaluation order for variants is recursive arguments last ? Or one should let the user choose ? It is strange to note that records are less problematic since you can permutte the field to choose yourself the evaluation order ... may be variant should have only one argument and list should be type 'a record_list = Cons of { car : 'a; cdr : 'a list } | Nil > Consider an explicit implementation of lists: > > type 'a list = Cons of 'a * 'a list | Nil > > Now, you'd write the list [ a; b; c; d ] (where a, b, c and d could be complex expressions) as > > Cons (a, Cons (b, Cons (c, (Cons (d, Nil))))) > > You need to have Cons (d, Nil) before you can construct Cons (c, ...) etc. It's the innermost expression, so evaluating it first makes sense in any sensible evaluation order.