尝试到处搜索。使用参数string * string
查看 https://github.com/fsharp/FAKE/blob/master/src/app/Fake.IIS/IISHelper.fs#L64。尝试在 F# 代码中实例化并收到错误 FS0010:不兼容Lete 在表达式的这一点上或之前结构化构造。
这到底是什么,如何实例化?
string*string
是一对两个字符串,大致等于Tuple<string, string>
。 然后string*int*decimal
大致等于 Tuple<string, int, decimal>
。
使用以下表达式创建string*string
的实例 "first", "second"
。string*int*decimal
的实例是这样创建的"1", 2, 3.0M
.
有关元组的详细信息,请参阅:https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/tuples
如果您认为 F# 具有用于创建类型的代数,则更容易看出此表示法的基本原理; *
创建元组,|
创建联合。
// Tree is roughly equal to having an interface Tree
// with three implementations Empty, Leaf and Fork
type Tree<'T> =
| Empty
| Leaf of 'T
| Fork of Tree<'T>*Tree<'T>
拥有用于类型创建的代数非常强大,正如 Scott Wlaschin 所演示的那样: https://fsharpforfunandprofit.com/ddd/