Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Created March 1, 2012 01:47
Show Gist options
  • Select an option

  • Save dtchepak/1946533 to your computer and use it in GitHub Desktop.

Select an option

Save dtchepak/1946533 to your computer and use it in GitHub Desktop.
recursive zipwith
zipWith' :: (a -> b -> c) -> [a] -> [b] -> [c]
zipWith' _ [] _ = []
zipWith' _ _ [] = []
zipWith' f (a:as) (b:bs) = (f a b):(zipWith' f as bs)
@OJ

OJ commented Mar 1, 2012

Copy link
Copy Markdown
-- your first two cases aren't required, just match against anything else
-- but match against the valid case first
zipWith' f (a:as) (b:bs) = f a b : zipWith' f as bs
zipWith' _ _ _ = []

@dtchepak

dtchepak commented Mar 1, 2012

Copy link
Copy Markdown
Author

@OJ Nice pickup. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment