
Hello all, in the continuation monad, I can turn a value into a Cont by means of return. Conversely I can convert a Cont into a value by passing id as the continuation. This dualism of Cont and plain values is well known. The bind operator kind of(!) takes a value a and produces a new value b. This is all wrapped in Cont stuff, so the result of bind is not really a plain a, but a Cont which takes a function from b -> r. But this is just the same dualism as above. Most Cont examples I've seen could much more easily be implemented with just values or calling functions on values. Then again there is "a poor man's concurrency" which I don't get at all. In between there is a huge gap of (my) understanding. Can someone help me cross this gap? There must be certain things I can do with Conts which I cannot do easily with values and functions.

martin
writes:
Can someone help me cross this gap? There must be certain things I can do with Conts which I cannot do easily with values and functions.
Any function can be turned into a function accepting a continuation: f :: a -> b f_cont :: a -> (b -> c) -> c The Cont construction abstracts this pattern into its own type: f_Cont :: a -> Cont c b The advantage is that we now have a Functor instance over 'b', rather than over 'c' (for Functor (->) applied to f_cont). I cover Cont is more detail here, with a reference to green threading at the very bottom: https://www.fpcomplete.com/user/jwiegley/understanding-continuations John
participants (2)
-
John Wiegley
-
martin