2006.04.18 Sinking Into OCaml Continuations Madness

A while back it was announced on the OCaml mailing list that someone had created a userland delimited continuations library for OCaml. I love OCaml, and I love Continuations... so I thought I'd give it a try. Ultimately going for the HTTP re-inversion trick, of course.

Little did I know what sort of a rabbit hole I was going down with Delimited Continuations. On the surface it doesn't seem that that big of a deal -- they're a lot like "normal" continuations (using call/cc or whatnot), except better. Instead of secretly being a function invocation that never returns, they are secretly a continuation that does.

At least thats what I've told myself. Unfortunately my brain doesn't like the explanations I've come accross so far. It makes perfect sense when I stand back a bit, but once I start trying to pound this keyboard to produce some code nothing seems to make sense. The best introduction I found so far is a composable continuations tutorial on the Community Scheme Wiki. Some heavier readings (such as A Monadic Framework for Delimited Continuations, on which the OCaml library is based) are a bit too fast-paced. Individual sentences are fine... but taken as a whole I'm not getting it.

Part of the problem is that when building Continuity (or its predecessor, Contize), I have actually been using coroutines rather than continuations, which simplify the situation a bit. So I haven't had to really deal with scheme's call/cc, let alone the various delimited versions such as shift/reset.

If it seems to you that I'm talking jibberish, perhaps you feel my pain.

I am making a bit of progress though. With the above tutorial and a few other searches the concepts are slowly starting to sink in. Eventually I will be able to explain it all through lovely diagrams of call-stack manipulations. Basically thats all these texts are missing -- nice simple diagrams.


Blog Blog RSS Feed



Follow @awwaiid



Wiki Edits Wiki RSS Feed

... more changes