作者:钟孝健V | 来源:互联网 | 2022-12-13 20:17
我正在通过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
最后一部分要求用zipWith来编写zip.我无法提出解决方案.老实说,我无法完全掌握这个问题(以秒为单位编写一个函数,当不需要第二个函数应用时,因为它首先需要所有参数).谢谢您的帮助.
1> Cirdec..:
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
也许myzip1
并且myZipWith f
对某些人来说是一样的f
.
myzip1 = myZipWith f
怎么会f
这样
(f x y) = (x, y)