F# filter function - first argument's condition seems to be reversed
I have a little weird experience with F# filter function today. The code is:
let rec filter : ('a -> bool) -> 'a list -> 'a list =
fun isKept -> function
| [] -> []
| (x::xs) -> if isKept x then x::filter isKept xs
else filter isKept xs
let x = filter ((>) 1) [1; -5; -20; 30; -35; 40]
That code returns
val x : int list = [-5; -20; -35]
Problem is, as I pass a condition in the first argument (> 1), I expect it
would filter out any list elements of the second argument that are greater
1, not the reverse.
Is there anything obviously clear that I couldn't spot?
No comments:
Post a Comment