edu.rice.cs.plt.recur
Class ComposedContinuation<T,R>

java.lang.Object
  extended by edu.rice.cs.plt.recur.PendingContinuation<R>
      extended by 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>) 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.


Constructor Summary
ComposedContinuation(Continuation<? extends T> first, Lambda<? super T,? extends Continuation<? extends R>> rest)
           
 
Method Summary
<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.
 Continuation<? extends R> step()
          If first is resolved, apply rest to compute the second.
 
Methods inherited from class edu.rice.cs.plt.recur.PendingContinuation
isResolved, value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComposedContinuation

public ComposedContinuation(Continuation<? extends T> first,
                            Lambda<? super T,? extends Continuation<? extends R>> rest)
Method Detail

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>