问题描述
在 F# 中不可能为结构元组定义类型别名。只有一种解决方法,它才有效。
let x = struct (1,2)
> val x : struct (int * int) = struct (1,2)
let y : struct (int * int) = struct (4,5) // explicit type
> val y : struct (int * int) = struct (4,5)
type S = struct (int * int) // straight deFinition
> error FS0010: Unexpected symbol '(' in member deFinition
type S = ValueTuple<int,int> // workaround
> [<Struct>]
type S = struct (int * int)
“type S = struct (int * int)”的错误是编译器错误吗?
解决方法
尝试提交错误并在此处找到答案:https://github.com/dotnet/fsharp/issues/7014
类型周围需要括号:
type Alias = (struct(int * int))