I am reading a F # tutorial and come across an example of syntax that I don't understand. The link to the page I'm reading is below. Here is an example from this page:
let rec quicksort2 = function
| [] -> []
| first::rest ->
let smaller,larger = List.partition ((>=) first) rest
List.concat [quicksort2 smaller; [first]; quicksort2 larger]
// test code
printfn "%A" (quicksort2 [1;5;23;18;9;1;3])
The part that I do not understand is this: ((>=) first). What exactly is this? For comparison, this is an example from the MSDN documentation for List.partition:
let list1 = [ 1 .. 10 ]
let listEven, listOdd = List.partition (fun elem -> elem % 2 = 0) list1
printfn "Evens: %A\nOdds: %A" listEven listOdd
The first parameter (is this the correct terminology?) On List.partition, obviously, is an anonymous function. I rewrote the specified line as follows:
let smaller,larger = List.partition (fun e -> first >= e) rest
and it works the same as in the example above. I just don't understand how this construct does the same thing:((>=) first)
http://fsharpforfunandprofit.com/posts/fvsc-quicksort/
source
share