Um… new to SML, still getting my feet wet.
MRE:
Exception Failure
fun knapsack(0,xs) = 0
| knapsack(a,[]) = raise Failure
| knapsack(a,(x,y)::xs) =
if x > a then
knapsack(a,xs)
else
x+knapsack(a-x,xs)
fun main() =
let
val l = [(20, 9), (17, 8), (14, 7), (10, 6), (8, 5), (6, 3)]
val c = 20
in
knapsack(c,l)
end
Error:
knapsack.sml:1.2 Error: syntax error: inserting INFIX
/usr/lib/smlnj/bin/sml: Fatal error -- Uncaught exception Compile with "syntax error" raised at ../compiler/Parse/main/smlfile.sml:15.24-15.46
I’m guessing the ::
operator is the culprit, but I can’t figure out what is wrong.