Created
June 20, 2011 14:38
-
-
Save 23Skidoo/1035724 to your computer and use it in GitHub Desktop.
zipWith with variable number of arguments
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
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