Skip to content

Instantly share code, notes, and snippets.

@dagit
Created January 15, 2014 00:07
Show Gist options
  • Save dagit/8428444 to your computer and use it in GitHub Desktop.
Save dagit/8428444 to your computer and use it in GitHub Desktop.
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