Monadic Call/CC?

Richard Uhtenwoldt ru@river.org
Fri, 22 Feb 2002 01:36:57 -0800


Ashley Yakeley writes:

>Now here's the interesting thing. The usual way to represent "real-world" 
>functions (i.e. with side-effects, or changing the world) from a to b is 
>to define a special _type constructor_, 'IO', and define the function as 
>'a -> IO b'. But an alternative, would have been to define a special 
>_type_, Action, and define the function as 'a -> (b -> Action) -> 
>Action'. And then your 'main' function has type 'Action'.
>
>Nor do we have to declare special >>= and return functions as we do for 
>IO.

Yeah, it's called continuation-passing style (CPS).

(b -> Action) is the type of the continuation argument.

>...and note that we get Peirce continuations for free:
>
>    peirce foo cont = foo (\a _ -> (cont a)) cont; -- constructors removed

Yeah, in CPS, call/cc is easy to write.

So, congratulations, you've written call/cc in Haskell. I think.
So, what I said this afternoon, namely, that call/cc is
"not something an implementation is likely
to be able to support unintentionally", I now have to retract.
I think.

I guess the call/cc you wrote last night in terms of catch and a ref
didn't work too well; huh?