使用 .NET 类时,有些情况下我们不需要使用括号来传递单个参数,例如:
let foo = DirectoryInfo "boo"
但是在使用单个参数时,稍微复杂了一些,我们确实需要括号... 有人知道当这种情况发生时的解析规则吗?
let foo = DirectoryInfo "boo"
但是在使用单个参数时,稍微复杂了一些,我们确实需要括号... 有人知道当这种情况发生时的解析规则吗?
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
想了解更多有关此样式的信息,请查看MSDN上的元组。
现在,还有另一种略有不同的方法,可以让函数看起来像是接受多个参数。这被称为柯里化,当仅处理F#代码时,您会更经常看到它。以下是一个快速示例。
FileSystemWatcher
,这个编译是没有问题的:let watcher = new FileSystemWatcher "blah"
- wsanville