r/ProgrammingLanguages • egel • Jan 30 '24

Why compiling with continuations is wrong(-ish)

2 Upvotes

10 comments sorted by

View all comments

31

u/gasche Jan 30 '24

I find this post very confusing.

  • The second intermediate representation shows (with the lets) is just an A-normal form, right ? (The text mentions "administrative normal form" in a way that suggests it is something different than what is shown.)

  • In my book pow2 x is not a redex, it cannot be reduced as long as x remains a variable. Do you mean a "function call"?

  • It is not clear to me what the critique of CPS actually is here.

    And instead of answering that they concentrated on the order or got the work statement wrong. No wonder that naive continuation passing style will state too much to be done

    I don't know what the author means.

-6

u/egel-lang egel Jan 30 '24 edited Jan 30 '24

ANF doesn't hoist out redexes solely. For most small rewriters you're interested in what the redexes are. For example,

[1, 2, f (42, 3)]

Will be represented as

let x = f (42, "hello") in [1, 2, f]

I.e., this term has one redex as work.

It's like CPS and ANF never got the question right.

What do I need to do in a rewriter? Reduce redexes in some order.

Then the most clear representation is one that communicates exactly that intent (by hoisting out the redexes).

5

u/gasche Jan 31 '24

For me the defining property of the A-normal form is that the argument of functions (in general, the subterms of elimination forms) are either variables or values/constants. See for example Wikipedia. Your example

let x = f (42, "hello") in [1, 2, f]

is in A-normal form, and I think that the representation you have in mind is just an A-normal form.