Partial function application for a non-symmetric operator using point-free style in F#?

前端 未结 2 1249
醉话见心
醉话见心 2020-12-11 19:01

How can I create a partial function application for a non-symmetric operator such as the modulus operator with regards to the first argument without any argument names in F#

2条回答
  •  悲哀的现实
    2020-12-11 19:08

    You can define flip function which is common in point-free style:

    let inline flip f x y = f y x
    

    and use it like this:

    let (%-) = flip (%)
    let mod10 = (%-) 10
    

    or directly like this:

    let mod10 = flip (%) 10
    

    Point-free style is not always readable (as in this example) and not popular in F# programming.

提交回复
热议问题