Created
April 22, 2015 03:54
-
-
Save ijoshsmith/8cf1cff07b62fdf14056 to your computer and use it in GitHub Desktop.
Haskell zip function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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