Sun Dec 18 11:14:07 EST 2011

Continuation Monad & compilation

It looks like the continuation monad is a very important/useful
abstraction for compiling tree structures with lexically scoped
identifiers, especially when you want to have an idea of "current
context" in which those identifiers are defined, i.e. the operation:

  Insert at current point in the subtree a definition of identifier ID
  and evalate the rest of the syntax generation in a deeper subtree
  that cannot escape the context of this definition.

Essentially what a continuation monad can do, used in this way (as a
partial continuation) is to make sure that subsequent continuation
manipulations can't escape a subtree.

I find this remarkable to the point of leading me to change my mental
picture of a partial continuation as a "guaranteed consistent context".

What I don't understand though is why partial continuations appear so
naturally in Haskell's contunation monad.  Maybe the way I'm using it
in the meta/dspm compiler is just a bit ad-hoc special-cased for this
to show up that way..