F# 中的类型 "string * string" 是什么意思?

  • 本文关键字:string 是什么 类型 f#
  • 更新时间 :
  • 英文 :


尝试到处搜索。使用参数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/

最新更新