【发布时间】:2012-05-09 13:06:49
【问题描述】:
我正在尝试将列表头 (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
【问题讨论】: