类型"字符串*字符串"在F#中意味着什么?

时间:2017-10-10 20:15:43

标签: f#

到处搜寻。 使用参数string * string查看https://github.com/fsharp/FAKE/blob/master/src/app/Fake.IIS/IISHelper.fs#L64。 试图在F#代码中实例化并收到错误FS0010:Incomp 在表达式中此点或之前的结构构造。

这个世界是什么以及如何实例化这个?

1 个答案:

答案 0 :(得分:6)

string*string是一对两个字符串,大致等于Tuple<string, string>string*int*decimal大致等于Tuple<string, int, decimal>

使用以下表达式string*string创建"first", "second"的实例。 string*int*decimal的实例创建类似于"1", 2, 3.0M

有关元组的更多信息,请参阅:https://docs.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/

相关问题