caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Damien Doligez <Damien.Doligez@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Evaluation Order
Date: Sun, 10 Jun 2001 19:59:11 +0200 (MET DST)	[thread overview]
Message-ID: <200106101759.TAA0000023297@beaune.inria.fr> (raw)

>From: Brian Rogoff <bpr@best.com>

>No, this is a language problem. Lots of people who teach OCaml have mentioned 
>that this is an issue. If the clash with expectation is so great then that
>You should always be careful about sequencing in imperative style programming, 
>but IMO this is one of those few things that SML does right that OCaml does 
>not. As you say, there is a very strong expectation that events occur in
>the order that we read them. The original arguments about optimizations
>and parallelism don't seem to have borne fruit, so it would be good to fix
>this.

The original argument about optimizations is still as valid as it ever
was.  The real problem is that there is a conflict between
left-to-right evaluation order and currying.  Consider the expression:

   f e1 e2 e3

It only looks like the application of f to 3 arguments.  In reality,
it is a nested expression with three function applications.  If you
want to evaluate it in left-to-right order, you have to do the
following:

1. evaluate f
2. evaluate e1
3. evaluate f (e1)   (call the result f1)
4. evaluate e2
5. evaluate f1 (e2)  (call the result f2)
6. evaluate e3
7. evaluate f2 (e3)

If you want to optimize this to get something as efficient as O'Caml
currently is, you have to know that f doesn't do any side-effect
before receiving all its arguments, which is generally impossible.
With right-to-left, the compiler doesn't have to know anything about f.

For years I thought that the only solution to this problem would be to
move away from currying by changing the preferred programming style to
passing tuples or records (as SML does).  But people at INRIA are
overly fond of currying for some reason.

Now I think there's another solution.  Let's just have different
semantics for  (f e1 e2 e3)  and  ((f e1) e2 e3) :

f e1 e2 e3 should evaluate f, then e1, then e2, then e3, then do a
ternary application.

(f e1) e2 e3 should evaluate f, then e1, then do a unary application,
then evaluate e2, then e3, then do a binary application.


I think this solution should work, and retain all the efficiency of
O'Caml.  The question is, how much does it interfere with labels and
optional arguments ?

-- Damien
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


             reply	other threads:[~2001-06-10 17:59 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-10 17:59 Damien Doligez [this message]
2001-06-10 18:28 ` Dave Mason
  -- strict thread matches above, loose matches on Subject: below --
2009-06-14 16:36 evaluation order Christophe Raffalli
2009-06-14 19:40 ` [Caml-list] " Jon Harrop
2009-06-14 21:12   ` Christophe Raffalli
2001-06-15 17:00 [Caml-list] Evaluation Order Manuel Fahndrich
2001-06-10  2:44 David McClain
2001-06-10  2:48 ` Patrick M Doane
2001-06-10  5:51   ` David McClain
2001-06-09 15:59 David McClain
2001-06-09 20:17 ` Brian Rogoff
2001-06-09 23:12   ` David McClain
2001-06-09 23:28     ` David McClain
2001-06-10  1:04       ` Dave Mason
2001-06-10  2:25         ` David McClain
2001-06-11 13:03           ` Dave Mason
2001-06-12 17:55             ` John Max Skaller
2001-06-13 16:54               ` Frederick Smith
2001-06-13 21:43                 ` John Max Skaller
2001-06-10  1:06       ` Charles Martin
2001-06-10  2:27         ` David McClain
2001-06-10 11:18         ` Tore Lund
2001-06-10 13:11           ` Tore Lund
2001-06-10 14:31           ` John Max Skaller
2001-06-12 15:12             ` Pierre Weis
2001-06-10 10:40       ` Joerg Czeranski
2001-06-10 14:06       ` John Max Skaller
2001-06-11 12:59         ` Dave Mason
2001-06-12 17:34           ` John Max Skaller
2001-06-10 13:47   ` John Max Skaller
2001-06-10 16:47     ` Brian Rogoff
2001-06-10 17:27       ` Dave Mason
2001-06-12 16:10       ` John Max Skaller
2001-06-09 23:19 ` John Max 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=200106101759.TAA0000023297@beaune.inria.fr \
    --to=damien.doligez@inria.fr \
    --cc=caml-list@inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).