discriminated-union

    1热度

    1回答

    我有一个Option类型: type Option<'a> = | Some of value:'a | None type MyString = string // Syntax type type-name = | case-identifier1 [of [ fieldname1 : ] type1 [ * [ fieldname2 : ] type2

    0热度

    1回答

    任何人都可以在TypeScript(2.4.1)中解释以下行为吗? 场景:我有一个可能是“红色”或“红色和圆形”(修改)的按钮。我想有以下语法来形容它: button.mods = "red"; button.mods = ["red", "round"]; button.mods = { red: true, round: false }; 来形容这一切,我用了以下接口: interfa

    1热度

    1回答

    可以说我有一个区分联合,像这样: type Route = HomeRoute | ProfileRoute | BlogRoute; type HomeRoute = { route: '/home' } type ProfileRoute = { route: '/profile/:userId', params: { userId: str

    3热度

    1回答

    我的F#代码的某些功能接收到的值作为对象装箱,即使底层值是键入的。如果这个值是一个有区别的联合,那么就不可能将它重新装回到它的F#类型中。下面是一个简单的例子: type Result<'TOk,'TError> = | Ok of 'TOk | Error of 'TError type ResultA = Result<string, int> let a = Ok "A" le

    0热度

    1回答

    我有一个XML文档,其中包含一系列重复的地址,其实际内容取决于所包含枚举的值。我想这是一种“标签联合” [或“可识别联合”?]: { <AddressList> <Address> <AddressType type="addressEnum" fixed="CanadianAddress"/> <AddressValue> <Street typ

    0热度

    1回答

    锈病documentation gives this example我们在那里的Result<T, E>实例名为some_value: match some_value { Ok(value) => println!("got a value: {}", value), Err(_) => println!("an error occurred"), } 有没有办法从so

    1热度

    1回答

    我有学校类(2层构造)识别联合: type School(name, antiquity) = member this.Name: string = name member this.Antiquity: int = antiquity new(name) = School(name, 0) 而各类建筑: type Building = | House |

    3热度

    2回答

    我有一个地图,其键可能采取各种形状(我正在使用“形状”松散)。为了处理这个我创建了一个可识别联合(DU): type AuxDataKey = | OneString of string | TwoStrings of string * string | OneStringInt of string * int | TwoStringsInt of

    5热度

    2回答

    如何创建OCaml/F#DU类型,其案例是其他案例的子集? 例如,我想创建一个包含不同符号声明类型的符号表,例如程序类型,变量和函数。乍一看,我可以看到一个变量包含它的类型,函数也包含一个类型和许多参数变量。所以我想用1 DU,而不是向分隔条件多条记录或别名: type Symbol = | TypeSymbol of id:string | VariableSymbol of

    2热度

    2回答

    F#中是否可能有一个区分的联合,其值只能被赋值一次?我想像的是这样的: type DogAttributes = { Age: int; Color: string; } type Dog = | Rex of DogAttributes ({ Age = 5; Color = "Brown"; } | Fido of DogAttributes ({ Age = 3; Color = "