Skip to content

Instantly share code, notes, and snippets.

@23Skidoo
Created June 20, 2011 14:38
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 23Skidoo/1035724 to your computer and use it in GitHub Desktop.
Save 23Skidoo/1035724 to your computer and use it in GitHub Desktop.
zipWith with variable number of arguments
module Main
where
-- See "Do We Need Dependent Types?" by Fridlender & Indrika
-- http://www.brics.dk/RS/01/10/
(<<) :: [a -> b] -> [a] -> [b]
(f:fs) << (a:as) = f a : (fs << as)
_ << _ = []
succF :: ([b] -> t) -> [a -> b] -> [a] -> t
succF n fs as = n (fs << as)
zero :: a -> a
zero = id
one :: [a -> b] -> [a] -> [b]
one = succF zero
two :: [a -> a1 -> b] -> [a] -> [a1] -> [b]
two = succF one
three :: [a -> a1 -> a2 -> b] -> [a] -> [a1] -> [a2] -> [b]
three = succF two
four :: [a -> a1 -> a2 -> a3 -> b] -> [a] -> [a1] -> [a2] -> [a3] -> [b]
four = succF three
zipWithN :: ([a] -> t) -> a -> t
zipWithN n f = n (repeat f)
f4 :: Num a => a -> a -> a -> a -> a
f4 a b c d = a + b + c + d
l :: [Integer]
l = zipWithN four f4 [1..] [2..] [3..] [4..]
main :: IO ()
main = print $ take 7 l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment