Created
January 15, 2014 00:07
-
-
Save dagit/8428444 to your computer and use it in GitHub Desktop.
N-ary zipWith: http://www.brics.dk/RS/01/10/BRICS-RS-01-10.pdf
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 Data.ZipWith where | |
import Prelude hiding (zipWith, succ) | |
infixl 5 << | |
(<<) :: [a -> b] -> [a] -> [b] | |
(f:fs) << (a:as) = f a : (fs << as) | |
_ << _ = [] | |
succ :: ([b] -> c) -> [a -> b] -> [a] -> c | |
succ = \n fs as -> n (fs << as) | |
zero :: a -> a | |
zero = id | |
one = succ zero | |
two = succ one | |
three = succ two | |
four = succ three | |
five = succ four | |
six = succ five | |
seven = succ six | |
eight = succ seven | |
zipWith :: ([a] -> b) -> a -> b | |
zipWith n f = n (repeat f) | |
-- example | |
ex1 = zipWith eight f as1 as2 as3 as4 as5 as6 as7 as8 | |
where | |
as1 = [1] | |
as2 = [2] | |
as3 = [3] | |
as4 = [4] | |
as5 = [5] | |
as6 = [6] | |
as7 = [7] | |
as8 = [8] | |
f a b c d e g h i = a + b + c + d + e + g + h + i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment