[Haskell-cafe] How to abort a computation within Continuation Monad?

Dimitry Golubovsky golubovsky at gmail.com
Thu Nov 22 01:01:02 EST 2007


Hi,

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
value.

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
------------------------------------

I have created a simple (pseudo) concurrency demo that runs in a web
browser, see the wiki page:

http://haskell.org/haskellwiki/Concurrency_demos/Haskell-Javascript_concurrency

Thanks.
-- 
Dimitry Golubovsky

Anywhere on the Web


More information about the Haskell-Cafe mailing list