Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
foldr2'cps _ z [] p k _ = k z
foldr2'cps f z (x:xs) p k k'
| p x = k' x
| otherwise = foldr2'cps f z xs p (\y -> k $ f x y) k'
main = do print $ foldr2'cps (++) [] [[1,2],[3,4],[5,6]]
(== []) id id
print $ foldr2'cps (++) [] [[1,2],[3,4],[],[5,6]]
(== []) id id
print $ foldr2'cps (+) 0 [1..10] (== 0) id id
print $ foldr2'cps (+) 0 [1..10] (== 5) id id
foldr2_cps _ z [] p k _ = k z
foldr2_cps f z (x:xs) p k k'
| p x = k' x
| otherwise = foldr2_cps f z xs p (\y -> k $ f x y) k'
main = do print $ foldr2'cps (++) [] [[1,2],[3,4],[5,6]]
(== []) id id
print $ foldr2'cps (++) [] [[1,2],[3,4],[],[5,6]]
(== []) id id
print $ foldr2'cps (+) 0 [1..10] (== 0) id id
print $ foldr2'cps (+) 0 [1..10] (== 5) id id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment