Skip to content

Instantly share code, notes, and snippets.

@thealmarty
Created January 1, 2019 19:14
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 thealmarty/0eaaf064a5ecbf38991b781f4b6ae4c4 to your computer and use it in GitHub Desktop.
Save thealmarty/0eaaf064a5ecbf38991b781f4b6ae4c4 to your computer and use it in GitHub Desktop.
A modified zip function in Haskell that sums up the two elements of the input lists in the second item of the output tuple.
--As modified from the Prelude:
zip_sum ::(Num a, Eq a)=> [a] -> [a] -> [(a,a)]
zip_sum [] _bs = []
zip_sum _as [] = []
zip_sum (a:as) (b:bs) = (a, (a + b) ) : zip_sum as bs
main = do
print (zip_sum [0,1,2] [1,2,3])
print (zip_sum [1,2,3,4,0,5,6] [1,2,3,4,5,6,0])
@thealmarty
Copy link
Author

See my blog post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment