Knocking down an anonymous function

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/

+4
source share
2 answers

: .

.

let x = a + b

+ a b. , , , +. , , , . , . :

let x = (+) a b     // same thing as a + b.

" ", :

let f = (+)
let x = f a b     // still same thing.

. :

let f x y = x + y

:

let a = f 5 6    // a = 11

"" , :

let a = f 5    // a is a function
let b = a 6   // b = 11

" " ( " " ) , .

:

let a = (+) 5    // a is a function
let b = a 6      // b = 11

:

(+) x    ===    fun y -> x + y

, , :

(>=) first     ===     fun y -> first >= y
+3

, infix
(.. )

, (>=) first - p >= first, "" , , , .

+5

Source: https://habr.com/ru/post/1660833/


All Articles