小编Lew*_*von的帖子

组合列表和单个项目时保护条件出错

我试图将list(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]]
Run Code Online (Sandbox Code Playgroud)

代码如下所示.

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 
Run Code Online (Sandbox Code Playgroud)

haskell guard

3
推荐指数
1
解决办法
295
查看次数

标签 统计

guard ×1

haskell ×1