Re:I'm Betting on Call-by-Push-Value
by mrkeen on Monday March 11, 2024 @06:47AM
(#39666489)
How do they figure out what goes into their environment, or how do their environments get populated?
I believe the first happens at compile time, and the second happens after the function is passed.
1 f x =
2 let xx = x * x in
3 (\y -> y + xx)
4
5 main = do
6 let clo = f 2
7 let applied = clo 3
8 print applied
The closure is defined on line 3, and instantiated on line 6.
xx is known to be the captured variable at compile time. But in a lazy setting, it's fine for the closure to be passed around before the value of xx is known:
f x =
let xx = trace "Evaluating xx" (x * x) in
trace "Returning closure" (\y -> y + xx)
main = do
let clo = f 2
let applied = clo 3
print applied
I believe the first happens at compile time, and the second happens after the function is passed.
The closure is defined on line 3, and instantiated on line 6.xx is known to be the captured variable at compile time. But in a lazy setting, it's fine for the closure to be passed around before the value of xx is known:
> Returning closure> Evaluating xx
> 7