问题描述
我一直认为F#有两种不同的传递参数的方式:咖喱风格和元组风格.这真的正确吗?
I've always thought that F# had two different ways to pass arguments, curry style and tuple style.Is this actually correct?
不是一种样式,咖喱样式和参数都可以是简单值或元组.
Isn't it simply one style , curry style, and arguments can either be simple values or tuples.
例如
someFunc (a,b) =
这不是带有 one 咖喱风格参数的函数,恰好是一个元组吗?因此,我可以使用pipleline运算符将元组传递给此函数吗?(元组元素的命名位置)
isn't this a function with one curry style argument which happens to be a tuple ?Thus allowing me to pass tuples to this function using the pipleline operator?(where the elements of the tuple is named)
(1,2) |> someFunc
这正确吗?
推荐答案
这将很好用-区别在于您拥有
This will work just fine - the difference is when you have
let f (a,b) = ...
let f2 a b = ...
然后,您可以轻松创建部分应用的f2,但是对于f来说,效果却不太理想-您必须这样做
then you can create a partially applied f2 easily, but for f it doesn't work quite as nicely - you have to do
let partial = fun t -> f (1,t)
let partial2 = f2 1
这篇关于F#参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!