On Thu, 2007-11-22 at 01:01 -0500, Dimitry Golubovsky wrote: > 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
This is more complicated than it needs to be. runCont (return 0) = \k -> k 0 so delimit f r = Cont $ \c -> f (c 0) r _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe