如何使用 zipWith(+) 添加两个数据类型 [[double]] 的列表?
How to add two list of data type [[double]] using zipWith(+)?
我在 Haskell 中这样做。我正在尝试添加两个要收集的列表,我正在使用 zipWith 函数来执行此操作。但是数据类型与我的添加功能不匹配。
这是我试过的
add :: [[Double]] -> [[Double]] -> [[Double]]
add = zipWith []
where zipWith :: (a -> b) -> [a] -> [b]
zipWith _ [] = []
zipWith [] _ = []
zipWith (+) (x:xs) (y:ys) = (+) x y : zipWith (+) xs ys
我想像这样添加两个列表
add [[1,2],[3,4]] [[10,20],[30,40]]
[[11,22],[33,44]]
zipWith (zipWith (+))
我想不需要进一步解释了吧?
我在 Haskell 中这样做。我正在尝试添加两个要收集的列表,我正在使用 zipWith 函数来执行此操作。但是数据类型与我的添加功能不匹配。
这是我试过的
add :: [[Double]] -> [[Double]] -> [[Double]]
add = zipWith []
where zipWith :: (a -> b) -> [a] -> [b]
zipWith _ [] = []
zipWith [] _ = []
zipWith (+) (x:xs) (y:ys) = (+) x y : zipWith (+) xs ys
我想像这样添加两个列表
add [[1,2],[3,4]] [[10,20],[30,40]]
[[11,22],[33,44]]
zipWith (zipWith (+))
我想不需要进一步解释了吧?