Last active
August 29, 2015 14:05
-
-
Save AndrasKovacs/3c285fc48579faa607db to your computer and use it in GitHub Desktop.
Polyvariadic zipWith.
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
{-# LANGUAGE | |
FlexibleInstances, | |
MultiParamTypeClasses, | |
UndecidableInstances, | |
IncoherentInstances, -- GHC 7.10 can do with only Overlapping | |
TypeFamilies #-} | |
class ZipWithN f t where | |
zipWithN' :: [f] -> t | |
instance t ~ [r] => ZipWithN r t where | |
zipWithN' r = r | |
instance (ZipWithN b t, t' ~ ([a] -> t)) => ZipWithN (a -> b) t' where | |
zipWithN' f = zipWithN' . zipWith ($) f | |
zipWithN :: ZipWithN f t => f -> t | |
zipWithN = zipWithN' . repeat | |
main = print $ zipWithN (*) [0..10] [0..10] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment