用zipWith编写zip

use*_*471 1 haskell

我正在通过Chris Allen和Julie Moronuki的Haskell编程书学习Haskell.需要有关压缩列表练习之一的帮助.练习有3个部分,前两个是关于编写我们自己的zip和zipWith的实现,我能够.

myzip1 :: [a] -> [b] -> [(a,b)]
myzip1 _ [] = []
myzip1 [] _ = []
myzip1 (x:xs) (y:ys) = (x,y) : myzip1 xs ys

myZipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
myZipWith _ _ [] = []
myZipWith _ [] _ = []
myZipWith f (x:xs) (y:ys) = (f x y) : myZipWith f xs ys
Run Code Online (Sandbox Code Playgroud)

最后一部分要求用zipWith来编写zip.我无法提出解决方案.老实说,我无法完全掌握这个问题(以秒为单位编写一个函数,当不需要第二个函数应用时,因为它首先需要所有参数).谢谢您的帮助.

Cir*_*dec 8

myzip1和之间的唯一区别myZipWith

myzip1      (x:xs) (y:ys) =   (x,y) : myzip1      xs ys
myZipWith f (x:xs) (y:ys) = (f x y) : myZipWith f xs ys
Run Code Online (Sandbox Code Playgroud)

也许myzip1并且myZipWith f对某些人来说是一样的f.

myzip1 = myZipWith f
Run Code Online (Sandbox Code Playgroud)

怎么会f这样

(f x y) = (x, y)
Run Code Online (Sandbox Code Playgroud)