subtyping

Wildcard pattern overriding subtype constraint on polymorphic variant

允我心安 提交于 2019-12-05 07:20:13
Given these types type a = [ `A ] type b = [ a | `B | `C ] and this function let pp: [< b] -> string = function | `A -> "A" | `B -> "B" | `C -> "C" applying a value of type a works without issue, as expected: let a: a = `A let _ = pp a However, if the function is modified to include a wildcard pattern let pp: [< b] -> string = function | `A -> "A" | `B -> "B" | _ -> "?" even though everything else remains the same, it now yields the following error (on let _ = pp a ): This expression has type b -> string but an expression was expected of type a -> 'a Type b = [ `A | `B ] is not compatible with

heterogeneous lists through flexible types

淺唱寂寞╮ 提交于 2019-12-04 14:29:43
问题 I am trying to stick heterogeneous types in a list making use of flexible types type IFilter<'a> = abstract member Filter: 'a -> 'a type Cap<'a when 'a: comparison> (cap) = interface IFilter<'a> with member this.Filter x = if x < cap then x else cap type Floor<'a when 'a: comparison> (floor) = interface IFilter<'a> with member this.Filter x = if x > floor then x else floor type Calculator<'a, 'b when 'b:> IFilter<'a>> (aFilter: 'b, operation: 'a -> 'a) = member this.Calculate x = let y = x |>

Tables whose sole purpose is specify a subset of another table

℡╲_俬逩灬. 提交于 2019-11-30 06:06:37
问题 The database I'm designing has an employees table; there can be multiple types of employees, one of which are medical employees. The database needs to also describe a many-to-many relation between medical employees and what competences they have. Is it okay to create a table medical_employees with only an id column, whose only purpose is to specify which employees are medics? The id column has a foreign key constraint that references the employees table. The code below should make my question

Tables whose sole purpose is specify a subset of another table

别说谁变了你拦得住时间么 提交于 2019-11-28 14:37:50
The database I'm designing has an employees table; there can be multiple types of employees, one of which are medical employees. The database needs to also describe a many-to-many relation between medical employees and what competences they have. Is it okay to create a table medical_employees with only an id column, whose only purpose is to specify which employees are medics? The id column has a foreign key constraint that references the employees table. The code below should make my question clearer: /* Defines a generic employee */ CREATE TABLE employees ( id INT PRIMARY KEY AUTO_INCREMENT,

TypeScript: why is a number assignable to a reference of type Object?

瘦欲@ 提交于 2019-11-28 07:34:49
问题 Why is this legal TypeScript? var x: number = 5 var y: Object = x Surely a number is not an Object . One might suspect that x is implicitly coerced (auto-boxed) to an object, but no: if (!(y instanceof Object)) { console.log(typeof y) } prints number For the record: $ tsc --version Version 1.8.10 回答1: Type compatibility in TypeScript is based on structural subtyping, not nominal typing. That said, consider the two following interface definitions: interface IFoo { X: number } interface IBar {

Conversion of pointer-to-pointer between derived and base classes?

眉间皱痕 提交于 2019-11-26 14:47:41
Regarding the following C++ program: class Base { }; class Child : public Base { }; int main() { // Normal: using child as base is allowed Child *c = new Child(); Base *b = c; // Double pointers: apparently can't use Child** as Base** Child **cc = &c; Base **bb = cc; return 0; } GCC produces the following error on the last assignment statement: error: invalid conversion from ‘Child**’ to ‘Base**’ My question is in two parts: Why is there no implicit conversion from Child** to Base**? I can make this example work with a C-style cast or a reinterpret_cast . Using these casts means throwing away