use*_*042 0 recursion haskell function list
到目前为止,我有:
miZipWith f [] [] = []
miZipWith f (x:xs) [] = []
miZipWith f [] (y:ys) = []
miZipWith f (x:xs) (y:ys) = f y: miZipWith f xs ys
----miZipWith f (x:xs) (y:ys) = f x : f y : miZipWith f xs ys
Run Code Online (Sandbox Code Playgroud)
但这只是用第二个列表"拉上"函数f.我如何包含第一个列表?
*Main> miZipWith (*2) [1,2,3,4] [5,6,1]
[10,12,2]
Run Code Online (Sandbox Code Playgroud)
该zipWith功能是这样的:
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
zipWith f (x:xs) (y:ys) = f x y : zipWith f xs ys
zipWith _ _ _ = []
Run Code Online (Sandbox Code Playgroud)
你的假设是函数f只接受一个参数,但它实际上需要两个参数(两个列表的头部).
| 归档时间: |
|
| 查看次数: |
662 次 |
| 最近记录: |