Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Christophe Raffalli <christophe.raffalli@univ-savoie.fr>
To: Ville-Pertti Keinonen <will@exomi.com>
Cc: Jon Harrop <jon@ffconsultancy.com>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Re: Parameter evaluation order
Date: Fri, 26 Aug 2005 19:00:21 +0200	[thread overview]
Message-ID: <430F4AA5.5000803@univ-savoie.fr> (raw)
In-Reply-To: <430F0CCF.3030103@exomi.com>

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.


  parent reply	other threads:[~2005-08-26 17:00 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-19 22:21 "Márk S. Zoltán"
2005-08-20  9:12 ` [Caml-list] " Alain Frisch
2005-08-26 17:53   ` "Márk S. Zoltán"
2005-08-22 16:50 ` Damien Doligez
2005-08-23  7:12   ` skaller
2005-08-23 11:29     ` Damien Doligez
2005-08-23 13:34       ` Igor Pechtchanski
2005-08-23 19:52         ` Damien Doligez
2005-08-24  1:24   ` Hao-yang Wang
2005-08-24 11:33     ` [Caml-list] " Damien Doligez
2005-08-24 14:39       ` Christophe Raffalli
2005-08-24 15:47         ` Berkeley DB Joel Reymont
2005-08-24 16:08         ` [Caml-list] Re: Parameter evaluation order brogoff
2005-08-24 20:05           ` Christophe Raffalli
2005-08-24 20:25             ` brogoff
2005-08-24 20:53               ` Jon Harrop
     [not found]               ` <430CE193.9000805@univ-savoie.fr>
2005-08-26  9:53                 ` Christophe Raffalli
2005-08-26 10:10                   ` Jon Harrop
2005-08-26 12:09                     ` Christophe Raffalli
2005-08-26 12:26                       ` Diego Olivier Fernandez Pons
2005-08-26 16:48                         ` Christophe Raffalli
2005-08-27 15:33                           ` Christophe TROESTLER
2005-08-26 12:36                       ` Ville-Pertti Keinonen
2005-08-26 14:17                         ` Fernando Alegre
2005-08-26 17:00                         ` Christophe Raffalli [this message]
2005-08-26 22:58                       ` skaller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=430F4AA5.5000803@univ-savoie.fr \
    --to=christophe.raffalli@univ-savoie.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=jon@ffconsultancy.com \
    --cc=will@exomi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox