函数中 (<) 是否有等价的模数?

ant*_*ers 0 f#

例如; 以下行

    |> Seq.filter(fun i -> i < 123)
Run Code Online (Sandbox Code Playgroud)

是一样的

    |> Seq.filter((<) 123)
Run Code Online (Sandbox Code Playgroud)

模运算符有这样的东西吗?我不确定第二个变体是什么,也找不到文档中引用的它,因此这使得搜索有些困难。所以为了奖励积分,请告诉我这个运营商叫什么!:)

目前使用:

|> Seq.filter (fun i -> i % 2 = 0)
Run Code Online (Sandbox Code Playgroud)

寻找类似的东西:

|> Seq.filter ((%) 2 = 0)
Run Code Online (Sandbox Code Playgroud)

小智 6

你的第一个例子说等于 是不正确fun i -> i < 123((<) 123)。这实际上相当于fun i -> 123 < i. 让我解释一下,每个运算符只是一个函数,只是中缀而不是前缀。举个例子

let (+) x y = x + y
let add x y = x + y

let (-) a b = a - b // notice that the first argument (a) is on the left side of the operator
let subs a b = a - b
Run Code Online (Sandbox Code Playgroud)

知道了这一点,我们就可以用%同样<的方式进行推理

let (%) x y = x % y
let (<) x y = x < y

// therefore
fun i -> i < 123

// is equivalent to
fun i -> (<) i 123

// and mathematically equiv to 
((>=) 123)

// same with %
fun i -> i % 2

// is equiv to
fun i -> (%) i 2

// thus cant be reduced to eliminate the lambda
Run Code Online (Sandbox Code Playgroud)