The continuation of k is a function that takes the result from evenk and does the "rest of the calculation" and produces a "response". What type of response has and what you mean by “the rest of the calculation” depends on what you use CPS for. CPS, as a rule, is not an end in itself, but is done for a specific purpose. For example, in the form of a CPS, it is very easy to implement control statements or optimize tail calls. Not knowing what you are trying to achieve, it is difficult to answer your question.
What is it worth if you are just trying to convert from a direct style to a continuation-transfer style, and all you care about is the value of the answer, which conveys the identification function, since the continuation has the right.
A good next step would be to implement evenk using CPS. I will make a simpler example. If I have a direct style function
let muladd xin = x + i * n
and if I accept CPS mulk and addk , I can write
let muladdk xink = let k' product = addk x product k in mulk ink'
And you will see that mractioniplication is executed first, and then “continues” with k' , which adds, and finally, continues with k , which is returned to the caller. The main idea is that in the body of muladdk I highlighted a new continuation k' , which denotes an intermediate point in the function of multiple additions. To make your evenk work, you will have to select at least one such continuation.
Hope this helps.
Norman ramsey
source share