Questions tagged [structural-types]
For questions about design and implementation of structural type systems, an approach to typing where types are sets of fields or methods and values having all those properties belong to the type
6
questions
6
votes
1
answer
284
views
How do you implement a structural subtyping checker?
In a structurally-typed language, one type is a subtype of another iff it has all of the fields/methods of the other with compatible types, meaning that field or return types are subtypes, parameter ...
4
votes
1
answer
166
views
Is it this easy to add nominal types to a structural type system?
Imagine a structural type system with the ability to create nominally-typed aliases:
type Foo = {foo: string, bar: number}
nominal type NominalFoo = Foo
Then the ...
4
votes
3
answers
170
views
How to support contravariant generics in a structural type system?
In a structural type system, a interface is just a list of properties with types and anything that has those properties automatically implements the interface. Typescript is one such example but it is ...
11
votes
1
answer
444
views
How can I have mutually-exclusive properties in a structural type system?
I have a structurally-typed object-oriented language, and I'd like to allow for types with some mutually-exclusive properties/attributes/slots/methods. That is, an object having more than one of these ...
10
votes
1
answer
207
views
How can optional properties be made sound in a static structural type system?
Typescript's structural type system is known to be (intentionally) unsound, in the sense that the value of an expression at runtime is not always necessarily assignable to its type determined at ...
15
votes
4
answers
422
views
How can polymorphism in a structural type system be compiled?
In a structural type system, a type can be assignable to another type without this relationship necessarily being declared. For example, in Typescript ...