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

Filter by
Sorted by
Tagged with
6 votes
1 answer
243 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 ...
Michael Homer's user avatar
  • 11.7k
2 votes
1 answer
137 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 ...
kaya3's user avatar
  • 17.1k
4 votes
3 answers
154 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 ...
mousetail's user avatar
  • 8,101
11 votes
1 answer
401 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 ...
Michael Homer's user avatar
  • 11.7k
10 votes
1 answer
181 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 ...
kaya3's user avatar
  • 17.1k
15 votes
4 answers
383 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 ...
kaya3's user avatar
  • 17.1k