Last active
January 15, 2019 19:16
-
-
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.
This file contains hidden or 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
-- | 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]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See my blog post.