Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created May 4, 2011 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jutememo/955465 to your computer and use it in GitHub Desktop.
Save jutememo/955465 to your computer and use it in GitHub Desktop.
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