Sat Jan 2 10:44:40 CET 2010
CPS and `if'
Indeed: it needs two control points: before and after the evaluation
of the condition.
(if a b c) ->
(if (a (lambda (v) (b k))
(lambda (v) (c k))))
Looks like CPS by itself isn't the problem. Representing the
resulting functional continuations as data is.
Here defunctionalization comes in: replace each lamba with a call to
(lambda (v) (b k))
-> (apply (Lambdaxxx v))
In the Danvy paper representation as closures and
defunctionalization are mentioned as separate approaches to
representing higher order functions:
* Closures: capture code pointers together with an environment
representing the free variable bindings.
* Defunctionalization: represent a higher order function as a data
structure containing the free variables.
* Combinators: translate a program into combinators (which eliminates
variable names) and use graph reduction.