Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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