我的F#代码的某些功能接收到的值作为对象装箱,即使底层值是键入的。如果这个值是一个有区别的联合,那么就不可能将它重新装回到它的F#类型中。下面是一个简单的例子: type Result<'TOk,'TError> =
| Ok of 'TOk
| Error of 'TError
type ResultA = Result<string, int>
let a = Ok "A"
le
我有学校类(2层构造)识别联合: type School(name, antiquity) =
member this.Name: string = name
member this.Antiquity: int = antiquity
new(name) = School(name, 0)
而各类建筑: type Building =
| House
|
我有一个地图,其键可能采取各种形状(我正在使用“形状”松散)。为了处理这个我创建了一个可识别联合(DU): type AuxDataKey =
| OneString of string
| TwoStrings of string * string
| OneStringInt of string * int
| TwoStringsInt of
如何创建OCaml/F#DU类型,其案例是其他案例的子集? 例如,我想创建一个包含不同符号声明类型的符号表,例如程序类型,变量和函数。乍一看,我可以看到一个变量包含它的类型,函数也包含一个类型和许多参数变量。所以我想用1 DU,而不是向分隔条件多条记录或别名: type Symbol =
| TypeSymbol of id:string
| VariableSymbol of
F#中是否可能有一个区分的联合,其值只能被赋值一次?我想像的是这样的: type DogAttributes = { Age: int; Color: string; }
type Dog =
| Rex of DogAttributes ({ Age = 5; Color = "Brown"; }
| Fido of DogAttributes ({ Age = 3; Color = "