开发者

Partial Application of Infix Functions in F#

开发者 https://www.devze.com 2022-12-15 11:27 出处:网络
In haskell it is posible to partially apply an infix function using sections, for instance given the开发者_如何学JAVA infix function < (less than) one can partially apply any of the function\'s arg

In haskell it is posible to partially apply an infix function using sections, for instance given the开发者_如何学JAVA infix function < (less than) one can partially apply any of the function's arguments: (5 <) , (< 5)

In other words, in haskell we have the following shorthand notation:

op :: a -> b -> c
(`op` y) === \x -> x `op` y
(x `op`) === \y -> x `op` y

Does F# have a similar concept?


No, neither of those (apart from standard partial application like (=) x).


Whereas I like the succinctness of Seq.find ((=) x), things like Seq.filter ((<) 3) (or even Seq.map (flip (-) 1)) are simply awkward to read and should immediately be replaced by a lambda expression, imo.


If you want to invent your own standards...

let lsection x f y -> f x y
let rsection f y x -> f x y

Then lsection 5 (<) === (5 <) and rsection (<) 5 === (< 5).

Though really, without language support, just put a lambda in there and it'll be clearer.

0

精彩评论

暂无评论...
验证码 换一张
取 消