[Haskell-cafe] How to abort a computation within Continuation
derek.a.elkins at gmail.com
Thu Nov 22 13:49:56 EST 2007
On Thu, 2007-11-22 at 01:01 -0500, Dimitry Golubovsky wrote:
> I finally was able to write a function which grabs the remainder of
> the computation in Cont monad and passes it to some function, in the
> same time forcing the whole computation to finish by returning a final
> I am not sure what kind of wheel I have reinvented, but here it is:
> -- Home-grown continuation delimiter function. Passes remainder of the
> -- whole computation to a given function and forces the whole computation
> -- to complete by returning a final value. Something similar to returning
> -- a final value in plain CPS instead of invoking the continuation.
> -- f: function which the remainder of the program will be passed to.
> -- Remainder will not be evaluated.
> -- r: final value of the whole computation that the latter will be
> -- terminated with.
> delimit f r = Cont $ \c -> runCont (return 0) $ \a -> f (runCont (return a) c) r
This is more complicated than it needs to be.
runCont (return 0) = \k -> k 0
delimit f r = Cont $ \c -> f (c 0) r
More information about the Haskell-Cafe