Skip to content

Instantly share code, notes, and snippets.

@ijoshsmith
Created April 22, 2015 03:54
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 ijoshsmith/8cf1cff07b62fdf14056 to your computer and use it in GitHub Desktop.
Save ijoshsmith/8cf1cff07b62fdf14056 to your computer and use it in GitHub Desktop.
Haskell zip function
-- Zips together two lists in Haskell.
zip' :: [a] -> [b] -> [(a, b)]
zip' xs [] = []
zip' [] ys = []
zip' (x:xs) (y:ys) = (x, y) : zip' xs ys
-- Example usages:
-- zip' "ABCDE" [1,2,3] …yields… [('A',1),('B',2),('C',3)]
-- zip' "AB" [1,2,3,4,5] …yields… [('A',1),('B',2)]
-- zip' "ABC" [] …yields… []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment