Skip to content

Instantly share code, notes, and snippets.

@jutememo
Created May 5, 2011 06:18
Show Gist options
  • Save jutememo/956626 to your computer and use it in GitHub Desktop.
Save jutememo/956626 to your computer and use it in GitHub Desktop.
foldr3' _ z [] p k _ = k z
foldr3' f'cps z (x:xs) p k k'
| p x = k' x
| otherwise = f'cps x (foldr3' f'cps z xs p k k') $ \y -> k y
main = do print $ foldr3' (\x y k -> k $ x ++ y) []
[[1,2],[3,4],[5,6]] (== []) id id
print $ foldr3' (\x y k -> k $ x ++ y) []
[[1,2],[3,4],[],[5,6]] (== []) id id
foldr3' _ z [] p k _ = k z
foldr3' f_cps z (x:xs) p k k'
| p x = k' x
| otherwise = f_cps x (foldr3' f_cps z xs p k k') $ \y -> k y
main = do print $ foldr3' (\x y k -> k $ x ++ y) []
[[1,2],[3,4],[5,6]] (== []) id id
print $ foldr3' (\x y k -> k $ x ++ y) []
[[1,2],[3,4],[],[5,6]] (== []) id id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment