You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be great if the standard type system could be a super set of the three type systems so that all of them could use it as a compilation target without losing typing information information.
Along the same lines of the C# in and out operator that controls variance in collections, here is an early exploration of what perhaps adding extra syntax to the type system could help us find a super set of the features of each.
Nullability
The ! operator, applied to a type, makes it NOT nullable. The ? operator, makes it nullable along the lines of this.
functionfoo(duck: !Duck){// duck makes it NOT nullable}functionfoo(duck: ?Duck){// duck makes it NULLABLE}
nominal versus structural types
We could add a ~ operator, called the "kindaof" operator (makes a "so so" floating hands) that, when applied to a type, makes it structural as opposed to nominal (and, similarly, a = operator, that makes it nominal). For example:
// treats duck as "a structural Duck"-like typefunctionfoo(duck: Duck~){duck.quack();}// This takes duck as a "nominal" duckfunctionfoo(duck: Duck=){duck.quack();}// ~Foo is a structural Foo.// NOTE(goto): maybe use @annotators, instead, like @structural interface Foo {}?interface~Foo{duck();}// =Foo is a nominal Foo.// NOTE(goto): maybe use @annotators, instead, like @nominal interface Foo {}?interface=Foo{duck();}
variance in collections
Along the same lines of the C# in and out operator, one could control the variance of a type explicitly via the in and out operator.
functionfoo(ducks: Array<inDuck>){// may "write" do ducks}functionfoo(ducks: Array<outDuck>){// only "reads" ducks}TODO(dimvar): helpmecomeupwithanexamplethat @gbrachasaid.// Takes duck in a contravariant wayfunctionfoo(duck: inDuck){}// Takes duck in a covariant wayfunctionfoo(duck: outDuck){}varcontravariantVar: Array<inDuck> = ["foo", "bar"];
var covariantVar: Array<outDuck> = ["foo", "bar"];
Optionality
functionfoo(?a: Duck){// makes a OPTIONAL}
enums?
Worst case configuration
In the worst case one want to control every single aspect of the type with the modifiers, which can be very ugly to type. Here is what it could look like:
function(?a: in!Duck~){// a is a Duck that is:// - optional// - not nullable// - covariant// - structural}
The text was updated successfully, but these errors were encountered:
It would be great if the standard type system could be a super set of the three type systems so that all of them could use it as a compilation target without losing typing information information.
Along the same lines of the C# in and out operator that controls variance in collections, here is an early exploration of what perhaps adding extra syntax to the type system could help us find a super set of the features of each.
Nullability
The ! operator, applied to a type, makes it NOT nullable. The ? operator, makes it nullable along the lines of this.
nominal versus structural types
We could add a
~
operator, called the "kindaof" operator (makes a "so so" floating hands) that, when applied to a type, makes it structural as opposed to nominal (and, similarly, a=
operator, that makes it nominal). For example:variance in collections
Along the same lines of the C# in and out operator, one could control the variance of a type explicitly via the in and out operator.
Optionality
enums?
Worst case configuration
In the worst case one want to control every single aspect of the type with the modifiers, which can be very ugly to type. Here is what it could look like:
The text was updated successfully, but these errors were encountered: