caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Frank Atanassow <franka@cs.uu.nl>
To: David McClain <barabh@qwest.net>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Error Reporting
Date: Mon, 1 Oct 2001 16:17:57 +0200	[thread overview]
Message-ID: <20011001161757.A29127@cs.uu.nl> (raw)
In-Reply-To: <004401c1483d$8d1bd160$210148bf@dylan>; from barabh@qwest.net on Fri, Sep 28, 2001 at 09:49:33AM -0700

David McClain wrote (on 28-09-01 09:49 -0700):
> > There must be a past history, or otherwise you would not be able to implement
> > function application.
> 
> I must confess that I don't understand this statement...
[..]
> But I suppose you are hinting that the compiler knows that all three of
> these closures are contained in the outermost one and so some record of
> activation history could be maintained by the compiler secretly plating
> static linkage information into each sub-closure. Not a bad idea! It
> certainly beats runtime computation of dynamic linkage and storing all that
> in a history queue.

Something like that. John Prevost gave a nice example.

In the CPS transform, in the case for application, you pass the continuation
of the application term to the operator, because the result of the application
has to be returned to the context of the call. That continuation is your past
history, since it tells you where you were before the function body was
evaluated.

In the case for a tail call, you don't return to the calling context; that is,
you discard the current continuation. Instead, (I think) you just pass the
function to itself, since so it serves as its own continuation.

So, for example, in

  let rec f x = if x=0 then 1 + g x else f (x-1)

you translate g x as

  [g x] = fun k -> [g] (fun g' -> [x] (fun x' -> g' k x'))

but f (x-1) as

  [f (x-1)] = fun _ -> [f] (fun f' -> [x-1] (fun x' -> f' f' x'))

Err... approximately at least. :) You will have to double-check this, but the
point is that distinction between these two cases gets obliterated in the
image of the translation, because no function _ever_ returns (as you
said).

Therefore, you have to add the error-handling information before you do the
transform, for example by turning continuations into an abstract datatype like
John did. Indeed, this is what you have to do anyway when you use CPS to
compile to machine code, since machines don't understand lambda-calculus, but
I assume you are compiling to Ocaml source.

Anyway, you might want to read this paper:

  The Essence of Compiling with Continuations
  Flanagan, Sabry, Duba, Felleisen
  http://citeseer.nj.nec.com/174731.html

which shows why CPS transformation is redundant, and it is better to do a
source-to-source transformation anyway. If you are really serious about this,
then you may also wish to check the Context (papers which reference this
paper) to see extensions of this idea.

-- 
Frank Atanassow, Information & Computing Sciences, Utrecht University
Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands
Tel +31 (030) 253-3261 Fax +31 (030) 251-379
-------------------
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


  parent reply	other threads:[~2001-10-01 14:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-28 16:49 David McClain
2001-10-01  0:52 ` John Prevost
2001-10-01 14:17 ` Frank Atanassow [this message]
2001-10-01 15:44   ` David McClain
  -- strict thread matches above, loose matches on Subject: below --
2001-09-27 13:32 Krishnaswami, Neel
2001-09-27 20:36 ` David McClain
2001-09-28 15:24   ` Frank Atanassow
2001-09-28 16:41     ` David McClain
2001-09-27 22:34 ` David McClain
2001-09-27 13:00 Damien Doligez
2001-09-26 22:55 David McClain

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=20011001161757.A29127@cs.uu.nl \
    --to=franka@cs.uu.nl \
    --cc=barabh@qwest.net \
    --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).