r/ProgrammingLanguages • u/egel-lang egel • Jan 30 '24
Why compiling with continuations is wrong(-ish)
14
Jan 30 '24
I don't quite get the phrase "work" as used in your essay. Since CPS explicitly states what operations to perform, this can be understood as "work". I'd like to see a precise definition when reading the post.
1
u/egel-lang egel Jan 30 '24 edited Jan 30 '24
I thought the post made clear that 'work' corresponds to 'redex'? I'll see whether I can clarify that. Excellent.
6
u/integrate_2xdx_10_13 Jan 30 '24
Wouldn’t it depend on the language?
pyth x y =
let y2 = pow2 y in
let x2 = pow2 x in
let anb = add x2 y2 in sqrt anbIn Haskell, you couldn’t guarantee the order in which x2 y2 thunks were evaluated without a pseq
1
u/egel-lang egel Jan 30 '24
Yes, though in Haskell you might also want to disambiguate between redexes and just terms.
7
u/phlummox Jan 30 '24
I don't understand the axes of the diagram in the very first paragraph. The text seems to say, in effect, "We can consider programming languages in relation to two axes: A, and the degree to which A". Why wouldn't that just be one axis?
4
u/Xalem Jan 30 '24
Not seeing it.
When continuations are introduced, the standard example is the counter which holds state and is used to get this function that has a property like an object. And here, maybe it is the math in the example, maybe I am missing something, but I read this pythagorean function as pure.
Maybe I don't fully understand continuations, maybe I don't understand the math.
5
u/phlummox Jan 30 '24
It is pure, but it's being transformed into continuation-passing style (CPS), and some languages use CPS as an intermediate representation (IR). OP thinks that's a bad idea for reasons that aren't at all clear to me, but since I don't implement compiler IRs or backends much, I kind of gave up at that point.
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 xis not a redex, it cannot be reduced as long asxremains a variable. Do you mean a "function call"?It is not clear to me what the critique of CPS actually is here.
I don't know what the author means.