Skip to content

Instantly share code, notes, and snippets.

@thalesmg
Created February 22, 2020 13:31
Show Gist options
  • Save thalesmg/8524bf898a9dca6020af3db40a1e1365 to your computer and use it in GitHub Desktop.
Save thalesmg/8524bf898a9dca6020af3db40a1e1365 to your computer and use it in GitHub Desktop.
There and back again (TABA)
-- https://doisinkidney.com/posts/2020-02-15-taba.html
zipRev :: [a] -> [b] -> [(a,b)]
zipRev xs ys = foldl f b ys xs
where
b _ = []
f k y (x:xs) = (x,y) : k xs
f k y [] = []
{-
zipRev [1,2,3] [10,20,30] =
foldl f b [10,20,30] [1,2,3] =
(f (f (f b 10) 20) 30) [1,2,3] =
(1,30) : (f (f b 10) 20) [2,3] =
(1,30) : (2, 20) : (f b 10) [3] =
(1,30) : (2, 20) : (3, 10) : b [] =
(1,30) : (2, 20) : (3, 10) : [] =
[(1,30), (2,20), (3,10)]
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment