-
-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Labels
Milestone
Description
Types such as (or (cons int int) (cons int symbol)) should be normalized to (cons int (or int symbol)). This looks like a homomorphism... maybe we can construct some sort of algebra for these types and then just have auto-derivations.
- merge unions of individual types to common type if it exists (t + nil = bool, int + float = number ...)
- normalize sums and intersections to always have sum on the top level (disjunctive normal form). This should also fix a lot of the weird infinite double recursions.
from typescript:
We normalize combinations of intersection and union types based on the distributive property of the '&'
operator. Specifically, because X & (A | B) is equivalent to X & A | X & B, we can transform intersection
types with union type constituents into equivalent union types with intersection type constituents and
effectively ensure that union types are always at the top level in type representations.
We do not perform structural deduplication on intersection types. Intersection types are created only by the &
type operator and we can't reduce those because we want to support recursive intersection types. For example,
a type alias of the form "type List<T> = T & { next: List<T> }" cannot be reduced during its declaration.
Also, unlike union types, the order of the constituent types is preserved in order that overload resolution
for intersections of types with signatures can be deterministic.