Gegeben eine list
von int
s, ich möchte die Summe aller Elemente in der list
, die einige Prädikaten p
erfüllen.F # Summierung aller Ints in einer Liste
Ich bin so weit gekommen, aber es ist noch nicht ganz da. Der Compiler beschwert sich über 0
mit der Meldung: The type 'int' does not match the type 'int list -> 'a''
let sum (p, xs) =
let rec sum' p xs tempSum = function
| [] -> tempSum
| x::xs -> sum' p xs tempSum + (if p x then x else 0)
sum' p xs 0
Was bin ich?
'List.filter p erforderlich ist |> List.sum'? –