Skip to content

Instantly share code, notes, and snippets.

@thealmarty
Last active January 15, 2019 19:16
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/643c0509dc6e7e4ad6bcd05e7dbb0e44 to your computer and use it in GitHub Desktop.
Save thealmarty/643c0509dc6e7e4ad6bcd05e7dbb0e44 to your computer and use it in GitHub Desktop.
The zip8 function, a function that zips 8 lists at once, in Haskell.
-- | The 'zipWith8' function takes a function which combines eight
-- elements, as well as eight lists and returns a list of their point-wise
-- combination, analogous to 'zipWith'.
zipWith8 :: (a->b->c->d->e->f->g->h->i) ->
[a]->[b]->[c]->[d]->[e]->[f]->[g]->[h]->[i]
zipWith8 z (a:as) (b:bs) (c:cs) (d:ds) (e:es) (f:fs) (g:gs) (h:hs)
= z a b c d e f g h : zipWith8 z as bs cs ds es fs gs hs
zipWith8 _ _ _ _ _ _ _ _ _ = []
-- | The 'zip8' function takes eight lists and returns a list of
-- eight-tuples, analogous to 'zip'.
zip8 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] ->
[g] -> [h] -> [(a,b,c,d,e,f,g,h)]
zip8 = zipWith8 (,,,,,,,)
--Print out some example results of zip8.
main = do
print (zip8 [1] [2] [3] [4] [5] [6] [7] [8])
print (zip8 [1] [1,2] [1,2] [1] [1] [1] [1] [1])
@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