axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-developer] Re: Literate programming and Provisos


From: Stephen Wilson
Subject: [Axiom-developer] Re: Literate programming and Provisos
Date: 08 Jul 2007 17:09:05 -0400
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4

Hi Ralf,

Ralf Hemmecke <address@hidden> writes:

> I am not so sure that I understand what a "continuation" is. I've
> already read some text about that, but I seem not to get the
> difference to Aldor's Generator concept. Maybe somebody can help. How
> would a continuation in Aldor look like and how would that be
> different from the Generator domain?

It is difficult to say what the best way to express such things in
Spad/Aldor would be.  This would require a lot of thought.  But there
is an obvious approach.

One can think of a continuation is an abstract object representing the
remainder of a computation.  We normally think about functions
returning values, with continuations we pass the value to the
remainder of the computation.  It is common to have a continuation
represented explicitly as an argument.  In Spad or Aldor, this might
be written as:

 add-cc (c : Continuation(Integer), n : Integer) : Integer ==
    c(n + 1)

There are issues with typing such things, as a function which calls a
continuation `never returns', but is not obliged to call the
continuation at all (and thus can return).  Here I just assumed that
Continuation is a built-in domain which is parametrized over the
argument type it expects.  It is possible to give a sound type to
continuations. ML supports them, for example.

You can represent effectively any control flow construct with
continuations, and as Tim mentioned, they have graceful connections to
multiprocessing.  Coroutines are a special case,  and Aldor style
generators are just a special case of coroutines.  Indeed, if I were
to implement coroutines/generators in Spad, I would seek a
continuation-passing-style (CPS) representation to aid reasoning about
the code.

On the other hand, some say continuations are the functional
equivalent to GOTO.  Its a powerful feature and it can be abused.

Wikipedia has some decent articles about continuations and
coroutines.  You might also consider playing with Scheme to get a feel
for them.

Sincerley,
Steve





  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]