How do you curry the 2nd (or 3rd, 4th, …) parameter in F# or any functional language?

前端 未结 5 1504
予麋鹿
予麋鹿 2021-02-19 06:58

I\'m just starting up with F# and see how you can use currying to pre-load the 1st parameter to a function. But how would one do it with the 2nd, 3rd, or whatever other paramet

5条回答
  •  一个人的身影
    2021-02-19 07:55

    OCaml, the language that F# was based on, has labeled (and optional) arguments that can be specified in any order, and you can partially apply a function based on those arguments' names. I don't believe F# has this feature.

    You might try creating something like Haskell's flip function. Creating variants that jump the argument further in the argument list shouldn't be too hard.

    let flip f a b = f b a
    let flip2 f a b c = f b c a
    let flip3 f a b c d = f b c d a
    

提交回复
热议问题