haskell - 如何使用 zipWith(+) 添加两个数据类型 [[double]] 列表?
问题描述
我在 Haskell 中这样做。我正在尝试添加两个要收集的列表,并且我正在使用 zipWith 函数来执行此操作。但是数据类型与我的 add 函数不匹配。
这就是我尝试过的
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 (+))
我认为不需要进一步解释?
推荐阅读
- mongodb - 如何使用 mongofiles 在 mongoDB Atlas 中保存文件(图像)?
- shell - 将文件从 1 个目录移动到其他目录
- flutter - 在 FLUTTER 的屏幕中央打印消息
- google-apps-script - 将 Google 文档评论连同突出显示的文本导出到 Google 表格中?
- c# - 使用对象列表反序列化 JSON
- r - change values of specific rows of a list of tibbles
- c# - 为什么我的 MassTransit 应用程序的代码更改会导致 MassTransit.RabbitMqTransport.RabbitMqConnectionException?
- python - python - 如何在Python中将关键项附加到.json文件?
- javascript - 选择正确的 JS 函数后隐藏内容
- python-3.x - 如何在 Python 3.7.3 中解析没有命名空间的 xml-string(不是文件)?