edu.rice.cs.plt.recur
Class ComposedContinuation<T,R>
java.lang.Object
edu.rice.cs.plt.recur.PendingContinuation<R>
edu.rice.cs.plt.recur.ComposedContinuation<T,R>
- All Implemented Interfaces:
- ResolvingThunk<R>, Thunk<R>, Continuation<R>
public class ComposedContinuation<T,R>
- extends PendingContinuation<R>
A continuation defined in terms of two other continuations, where the second is parameterized
by the result of the first. This class is essential to correctly handling general recursion.
Its step() and compose(edu.rice.cs.plt.lambda.Lambda super R, ? extends edu.rice.cs.plt.recur.Continuation extends S>>) methods are defined so that iterative computation
does not require "drilling down" to an unbounded depth in order to locate and perform the
next evaluation step.
|
Method Summary |
|
compose(Lambda<? super R,? extends Continuation<? extends S>> c)
Create a new ComposedContinuation with the same first, but with a rest
that will compose c onto the result of this object's rest function. |
Continuation<? extends R> |
step()
If first is resolved, apply rest to compute the second. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ComposedContinuation
public ComposedContinuation(Continuation<? extends T> first,
Lambda<? super T,? extends Continuation<? extends R>> rest)
step
public Continuation<? extends R> step()
- If
first is resolved, apply rest to compute the second. Otherwise,
invoke first.step(), and then "push" rest into the result by invoking
compose().
- Specified by:
step in interface Continuation<R>- Specified by:
step in class PendingContinuation<R>
compose
public <S> Continuation<S> compose(Lambda<? super R,? extends Continuation<? extends S>> c)
- Create a new
ComposedContinuation with the same first, but with a rest
that will compose c onto the result of this object's rest function.
(Note that the default behavior -- nesting this object in another ComposedContinuation
with c as its rest -- results in continuations whose step() methods
are invoked recursively to an unbounded depth.)
- Specified by:
compose in interface Continuation<R>- Overrides:
compose in class PendingContinuation<R>