【发布时间】:2017-11-02 06:06:15
【问题描述】:
好吧,看来我对 Haskell 很不满意,我发誓我一直被所有这些问题所困扰。无论如何,我需要取两个列表,压缩它们,然后用总和映射。所以这是我到目前为止所拥有的,但它不起作用:
zipMapList :: [a] -> [a] -> [a]
zipMapList x y = do
let zipList = zip x y
let mapList = map + zipList
mapList
好的,这是我尝试加载文件时遇到的错误:
HW2.hs:18:25: error:
• Couldn't match expected type ‘(a1 -> b) -> [a1] -> [b]’
with actual type ‘[(a, a)]’
• In the second argument of ‘(+)’, namely ‘zipList’
In the expression: map + zipList
In an equation for ‘mapList’: mapList = map + zipList
• Relevant bindings include
mapList :: (a1 -> b) -> [a1] -> [b] (bound at HW2.hs:18:9)
zipList :: [(a, a)] (bound at HW2.hs:17:9)
y :: [a] (bound at HW2.hs:16:14)
x :: [a] (bound at HW2.hs:16:12)
zipMapList :: [a] -> [a] -> [a] (bound at HW2.hs:16:1)
18 | let mapList = map + zipList |
HW2.hs:19:5: error:
• Couldn't match expected type ‘[a]’
with actual type ‘(a0 -> b0) -> [a0] -> [b0]’
• Probable cause: ‘mapList’ is applied to too few arguments
In a stmt of a 'do' block: mapList
In the expression:
do let zipList = zip x y
let mapList = map + zipList
mapList
In an equation for ‘zipMapList’:
zipMapList x y
= do let zipList = ...
let mapList = ...
mapList
• Relevant bindings include
zipList :: [(a, a)] (bound at HW2.hs:17:9)
y :: [a] (bound at HW2.hs:16:14)
x :: [a] (bound at HW2.hs:16:12)
zipMapList :: [a] -> [a] -> [a] (bound at HW2.hs:16:1)
19 | mapList | ^^^^^^^
我只是不明白错误的含义,我的意思是我得到了一个列表 [a] 和另一个列表 [a],然后我压缩它们并映射然后得到另一个列表,这对我来说没有意义为什么我收到元组错误,有人可以帮忙吗?
【问题讨论】:
-
"然后用总和映射" - 这是什么意思?你能添加一个示例输入和输出吗?
-
[1, 2, 3] [4, 5, 6] 被压缩到 [(1, 4), (2, 5), (3,6)],然后被映射到 [ 5、7、9]。
标签: list haskell zip syntax-error tuples