我正在尝试将列表头 ( r
) 添加到列表中sack
,但是我不断收到此错误消息。
ERROR "Knapsack.hs":35 - Type error in guarded expression
*** Term : findItems rt (r : sack) (getTotalWeight sack r)
*** Type : [Item]
*** Does not match : [[Item]]
代码如下所示。
findItems :: [Item] -> [Item] -> Float -> [Item]
findItems (r:rt) sack total
| total > 20 = [sack]
| canContinue = findItems rt (r : sack ) (getTotalWeight sack r)
| otherwise = [sack]
where canContinue = (getTotalWeight sack r) < 20