Skip to content

Instantly share code, notes, and snippets.

@AndrasKovacs
Last active August 29, 2015 14:05
Show Gist options
  • Save AndrasKovacs/3c285fc48579faa607db to your computer and use it in GitHub Desktop.
Save AndrasKovacs/3c285fc48579faa607db to your computer and use it in GitHub Desktop.
Polyvariadic zipWith.
{-# 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