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: Jon Harrop <jon@ffconsultancy.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Re: Parameter evaluation order
Date: Fri, 26 Aug 2005 14:09:13 +0200	[thread overview]
Message-ID: <430F0669.6050103@univ-savoie.fr> (raw)
In-Reply-To: <200508261110.41183.jon@ffconsultancy.com>

Jon Harrop a écrit :
> On Friday 26 August 2005 10:53, Christophe Raffalli wrote:
> 
>>This looks strange, because the semicolumn is used both to specify order
>>evaluation left-to-right in sequence and right-to-left in record.
> 
> 
> I haven't checked but it is probably undefined, rather than right-to-left in 
> records.
> 
> 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?
> 
> # [print_endline "1"; print_endline "2"];;
> 2
> 1
> - : unit list = [(); ()]
> 

yes I would ...

In fact, after though, the only place where evalauation order should be 
unspecified or better, specified right-to-left is function application 
and all other case (tuple, variants (and therefore list), should be 
left-to-right.

Let me explain:

- why function should be right-to-left:

because the syntax is somehow wrong, the argument should come first !
A good way to think about it is when you write the operationnal 
semantics of call-by-value

if v is a value then (fun x -> t) v evaluates t[x:=v]

in this sentence we are looking at v first.

Another point: if you use a stack (either to define the semantics or to 
implement), the left most argument should be on the top of the stack and 
therefore pushed last.

Why are most language left-to-right: because nobody wanted to reverse 
the notation of function aplpication :-) (and if you think, the standard 
notation for numbers should also be reversed ... and whe should read 
from right to left, which is what we do when we do an addition with 
paper and pencil)

- why other contructor (tuple, records, variants) should be 
left-to-right: because this is the most natural thing to do, and in fact 
there is no semantical reason to choose one evaluation order or another 
(except for variant constructor if you consider that they are function 
like others). (except that they are people around the world that writes 
right-to-left or top-to-bottom ... what are the camlp4 guys doing for 
this poor people ;-)

- why should the evaluation order be specified: this is needed if you 
want to formally reason about programs ... as far as I know. I had like 
to find a system where I can prove programs in call-by-value whatever 
evaluation order they use ... but I do not know how to do that, without 
proving programs for all the possible evaluation order as soon as the 
argument have side effect which is too much.

- Yes, this is a pity since you may want the compiler to interleave the 
code of the various arguments to fill the pileline. But I think doing 
this when the code has no side effect is enough (like with arithmetic 
expression in a + b + c, d + e + f).




  reply	other threads:[~2005-08-26 12:09 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 [this message]
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
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=430F0669.6050103@univ-savoie.fr \
    --to=christophe.raffalli@univ-savoie.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=jon@ffconsultancy.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