The sum of all positive numbers after the last non-negative can be calculated like this:
let lst = [-5; 4; -3; 2; 6; 10]
let afterLastNegative =
lst
|> List.rev
|> Seq.takeWhile (fun x -> x > 0)
|> Seq.sum
printfn "%A" afterLastNegative
List.rev reverses the list then Seq.takeWhile will take numbers while the function
fun x -> x > 0
is true, and it returns true if x is positive. Then Seq.sum simply sums all the numbers taken. A slighly shorter version would be:
let lst = [-5; 4; -3; 2; 6; 10]
let afterLastNegative =
lst
|> List.rev
|> Seq.takeWhile ((<) 0)
|> Seq.sum
printfn "%A" afterLastNegative
It does exactly the same. (<) is the name of the function operator lesser than and is partially applied with one operator, leaving the other to be supplied by the Seq.takeWhile function.