我们可以像type Address = Address of string使用展开功能一样展开类型
let unwrapAddress (Address a) = a
let addr = Address "sdf"
let str = unwrapAddress addr
Run Code Online (Sandbox Code Playgroud)
所以str类型string,但如果有这样的类型方法将无法正常工作:
type Composite = Composite of integer:int * someStr:string
let unwrap (Composite c) = c
Run Code Online (Sandbox Code Playgroud)
会产生错误
let unwrap (Composite c) = c;;
------------^^^^^^^^^^^
error FS0019: This constructor is applied to 1 argument(s) but expects 2
Run Code Online (Sandbox Code Playgroud)
我可以以某种方式将复合类型解包为一个简单的元组吗?