caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Dave Mason <dmason@sarg.Ryerson.CA>
To: "David McClain" <dmcclain1@mindspring.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Evaluation Order
Date: Sat, 09 Jun 2001 21:04:19 -0400	[thread overview]
Message-ID: <200106100104.VAA32072@sarg.Ryerson.CA> (raw)
In-Reply-To: Your message of "Sat, 09 Jun 2001 16:28:56 PDT." <000901c0f13b$f981c610$210148bf@dylan>

There is a solution to this problem.  I don't know if anyone has
proposed this before, but it would be hard to believe that it's novel.

The idea is to annotate the type of any functional result with the
fact that it has escaping side-effects.  Then to not let any
so-annotated value be used directly in an expression.  Let's look at
David's problem:

>>>>> On Sat, 9 Jun 2001 16:28:56 -0700, "David McClain" <dmcclain1@mindspring.com> said:

> My mistake was writing

> let ans = process_stream() + process_tail()

In what I'm proposing, the result type of both process_stream and
process_tail would be so annotated:
	process_stream : unit -> int effect
	process_tail   : unit -> int effect
and the compiler would give you a side-effect error with that
expression.  But using such a value which was a simple variable would
remove the annotation and apply it to the whole expression, so:

	let ans =
	 let ans1 = process_stream() in
	 let ans2 = process_tail() in
		ans1 + ans2

would work.  Note that the function containing this computation must
also be tagged as side-effecting when its results are used elsewhere.

This would be fairly easy to add to the compiler and would *not*
require us to have a specified execution order in expression
evaluation (a Good Thing(TM)) but would prevent you from making the
kind of error seen here.  The biggest problem is that this is not a
proper type, as I have described it, although it could go in the
module interfaces as such, and can be automatically propagated by the
compiler.

So then David could go back to trusting the ocaml type system to
protect him.  :-)

This would not be completely backward-compatible with existing ocaml
programs (a Bad Thing(TM)), but any programs that it would break would
be ones that currently depend on the existing evaluation order (a Very
Bad Thing(TM)), so forcing them to fix their programs would be a Good
Thing, and for a change, two wrongs would make a right!

> What is needed is some specification that indicates temporal
> preference, and then the type checking mechanism must be enhanced to
> keep temporal order.  Most programs in OCaml probably have no
> preference, and in fact, a sense of order is strongly discouraged in
> most FPL's -- e.g., Haskell.

I have a feeling that what I propose is somehow related to monads, but
in a way that ocaml programmers would not find intrusive and would
make our programs more robust.

(This could actually be made a little more more useful at the cost of
being a little more complex.  Instead of 'a effect, have at least
three annotations: 'a ref_effect, 'a io_effect, 'a assign_effect.  So
the types of some common operators would be:
	(:=) : 'a ref -> 'a -> unit assign_effect
	(!)  : 'a ref -> 'a ref_effect
	incr : int ref -> unit assign_effect
	printf : ('a, out_channel, unit) format -> 'a io_effect
Then you could have any number of ref_effects combined with at most
one io_effect, but assign_effects could not be combined with another
assign_effect, more than one io_effect, or any ref_effects.  This
would break a minumum number of existing programs, but still be safe.)

../Dave
-------------------
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-11 11:19 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
2001-06-10  2:44 David McClain
2001-06-10  2:48 ` Patrick M Doane
2001-06-10  5:51   ` David McClain
2001-06-10 17:59 Damien Doligez
2001-06-10 18:28 ` Dave Mason
2001-06-15 17:00 Manuel Fahndrich
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

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=200106100104.VAA32072@sarg.Ryerson.CA \
    --to=dmason@sarg.ryerson.ca \
    --cc=caml-list@inria.fr \
    --cc=dmcclain1@mindspring.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;
as well as URLs for NNTP newsgroup(s).