从列表中获取第3个元素的第一个元素和第二个元素 - Haskell
问题描述:
因此,我将一个3元组列表传递给该函数,并且想要返回该元组的第一个和第三个元素,为什么这里的代码不工作?从列表中获取第3个元素的第一个元素和第二个元素 - Haskell
remove :: (a, b, c) -> (a,c)
remove (x, _, y) = (x,y)
我得到的错误是
*** Expression : remove (sortScore b h)
*** Term : sortScore b h
*** Type : [(Val,Int,End)]
*** Does not match : (a,b,c)
答
sortScore
返回3元组列表,但remove
只接受一个。
您可以使用map
申请remove
给每个元素从sortScore
返回
map remove (sortScore b h)
答
您需要使用map
列表sortScore b h
变换每个元组:
map remove $ sortScore b h
不能将remove
只是sortScore b h
因为最后一个是列表,但remove
工作在元组上。
好了,我的意思是说第一和第三,让我编辑 – Sprout 2014-11-20 23:54:51