[英]F# constructor syntax
when using .net classes, there are cases when we don't need parenthesis to pass a single parameter like 当使用.net类时,有些情况下我们不需要括号来传递单个参数,例如
let foo = DirectoryInfo "boo"
but something a little more complicated using a single parameter, we do need parenthesis... does anyone know the parsing rules when this is true? 但是使用单个参数稍微复杂一些,我们确实需要括号...当这是真的时,是否有人知道解析规则?
In F#, all functions take a single parameter. 在F#中,所有函数都只使用一个参数。 Now this may be a little confusing at first, because you can have a function which appears to take more than one parameter, but you're actually passing a single parameter that is a tuple.
现在这可能有点令人困惑,因为你可以拥有一个似乎需要多个参数的函数,但实际上你传递的是一个元组的参数。
Here's a simple example of constructors that appear like they take more than 1 parameter: 这是一个构造函数的简单示例,它们看起来像是带有多个参数:
let foo = DirectoryInfo "boo" //passing 1 argument
let foo2 = DirectoryInfo ("boo") //passing 1 argument that is a tuple
let foo3 = StringBuilder ("blah", 100) //passing 1 argument again
let foo4 = StringBuilder "blah" 100 //does not compile
For more info about this style, check out Tuples on MSDN . 有关此样式的更多信息,请查看MSDN上的Tuples 。
Now, there also is another slightly different method of making it seem like a function takes more than 1 argument. 现在,还有另一种稍微不同的方法,使它看起来像一个函数需要超过1个参数。 This is called currying , which you will see more often when dealing only with F# code.
这称为currying ,在处理F#代码时,您会更频繁地看到它。 Here's a quick example of this.
这是一个简单的例子 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.