I am trying to add the list header ( r) to the list sack, however I keep getting this error message.
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]]
Below is the code.
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
You cannot return [sack]from findItems, because it sackalready has a type [Item], therefore it [sack]has a type [[Item]]. Remove the brackets.
[sack]
findItems
[Item]
[[Item]]
, ( [Item], ), ( ), Haskell , , , re , , [[Item]]. , | findItems. , , :)
|
, , "Hugs-ism", Hugs, , -, GHC. GHCi, , , :
| total > 20 = [sack]
GHCi ( IMHO, , , !).