Skip to content

Instantly share code, notes, and snippets.

@keizo042
Last active August 29, 2015 13:59
Show Gist options
  • Save keizo042/10568048 to your computer and use it in GitHub Desktop.
Save keizo042/10568048 to your computer and use it in GitHub Desktop.
zipWith 実装してみようと思ったけど上手くかね。わかんね。
--zipTwo :: ( a -> b -> c ) -> [a] -> [b] -> [c]
--zipTwo _ [] _ = []
--zipTwo _ _ [] = []
--zipTwo f (x:xs) (y:ys) = f x y : f xs ys
--分かった 再帰を使っているのに引数にとった関数を使おうとしているから
-- 上手くいかなかった
zipTwo :: (a -> b -> c) -> [a] -> [b] -> [c]
zipTwo f [] _ = []
zipTwo f _ [] = []
zipTwo f (x:xs) (y:ys) = f x y : zipTwo f xs ys
main = print ( zipTwo (+) [1..10] [1..10] )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment