here is a function multiplies the elements in a list using CPS style
mlist xx k = aux xx k
where aux [] nk = nk 1
aux (0:xs) nk = k 0
aux (x:xs) nk = aux xs $ \v -> mul x v nk
what if I change the ‘k’ to ‘nk’ in the expression aux (0:xs) nk = k 0, whats the difference between the two ?
kis always the original continuation passed tomlistwhereas for the list [1, 0]nkin that case will be\v -> mul 1 v k(from third case ofaux).If we assume
mulis defined asmul x y k = k $ x*y, this doesn’t make a practical difference sinceywill always be 0. But the actual method of arriving at that result is different (barring possible optimizations by the compiler).