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 C64EBBDD8 for ; Fri, 26 Aug 2005 16:17:49 +0200 (CEST) Received: from sark4.cc.gatech.edu (sark4.cc.gatech.edu [130.207.7.19]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j7QEHm4o024383 for ; Fri, 26 Aug 2005 16:17:49 +0200 Received: from gaia.cc.gatech.edu (gaia.cc.gatech.edu [130.207.3.8]) by sark4.cc.gatech.edu (8.12.10/8.12.8) with ESMTP id j7QEHkXH028726; Fri, 26 Aug 2005 10:17:46 -0400 (EDT) Received: (from fernando@localhost) by gaia.cc.gatech.edu (8.12.10/8.12.8) id j7QEHjFD022226; Fri, 26 Aug 2005 10:17:45 -0400 (EDT) Date: Fri, 26 Aug 2005 10:17:44 -0400 From: Fernando Alegre To: Ville-Pertti Keinonen Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Re: Parameter evaluation order Message-ID: <20050826141744.GC7595@gaia.cc.gatech.edu> 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> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <430F0CCF.3030103@exomi.com> User-Agent: Mutt/1.4.2.1i X-Miltered: at nez-perce with ID 430F248C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; gatech:01 caml-list:01 appending:01 val:01 char:01 26,:98 ...:98 wrote:01 expression:01 append:02 append:02 parameter:02 construct:02 element:02 element:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=DNS_FROM_RFC_ABUSE autolearn=disabled version=3.0.3 On Fri, Aug 26, 2005 at 03:36:31PM +0300, Ville-Pertti Keinonen wrote: > 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. Ignoring efficiency concerns, may I suggest that the correct way to build lists is by appending elements, not prepending them: # let append (element,list) = list @ [element];; val append : 'a * 'a list -> 'a list = # append('d', append('c', append('b', append('a', []))));; - : char list = ['a'; 'b'; 'c'; 'd'] This will evaluate in the right order. Fernando