Haskell CPS programming style issue

here the function multiplies the items in the list using the 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 'k' to 'nk' in the expression aux (0: xs) nk = k 0 , what is the difference between the two?

+3
source share
2 answers

kis always the original continuation passed in mlist, while for the list [1, 0] nkin this case it will be \v -> mul 1 v k(from the third case aux).

, mul mul x y k = k $ x*y, , y 0. ( ).

+4

, " " , , - "" .

+1

Source: https://habr.com/ru/post/1753811/


All Articles