diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-12-25 11:54:21 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-12-25 12:07:37 +0000 |
| commit | 1c0b88e256de6b4ea1b0c34ad525dfdad471f5ee (patch) | |
| tree | a3678272ef3be9d1e09c9e286dcb1957e7e2edd1 /src/main/java | |
| parent | 002aab32f5f68d5399a679100df40ffd8627c217 (diff) | |
Implement type substitution for constructed types
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/types/TypeSubstitution.java | 9 | ||||
| -rw-r--r-- | src/main/java/org/shedlang/compiler/types/Types.java | 7 |
2 files changed, 13 insertions, 3 deletions
diff --git a/src/main/java/org/shedlang/compiler/types/TypeSubstitution.java b/src/main/java/org/shedlang/compiler/types/TypeSubstitution.java index 27111fd5..a6719d17 100644 --- a/src/main/java/org/shedlang/compiler/types/TypeSubstitution.java +++ b/src/main/java/org/shedlang/compiler/types/TypeSubstitution.java @@ -9,9 +9,12 @@ public class TypeSubstitution { case BottomType bottomType -> type; - case ConstructedType constructedType -> { - throw new UnsupportedOperationException("TODO"); - } + case ConstructedType<?> constructedType -> new ConstructedType<>( + constructedType.constructor(), + constructedType.args().stream() + .map(arg -> substitute(arg, map)) + .toList() + ); case FunctionType functionType -> new FunctionType( functionType.positionalParams().stream() diff --git a/src/main/java/org/shedlang/compiler/types/Types.java b/src/main/java/org/shedlang/compiler/types/Types.java index c3c25853..0e502249 100644 --- a/src/main/java/org/shedlang/compiler/types/Types.java +++ b/src/main/java/org/shedlang/compiler/types/Types.java @@ -49,6 +49,13 @@ public class Types { return new TypeConstructor<>(params, genericType); } + public static <T extends StructuredType> Type constructedType( + TypeConstructor<T> constructor, + List<Type> args + ) { + return new ConstructedType<>(constructor, args); + } + public static Type commonSupertype(List<Type> subtypes) { var uniqueSubtypes = subtypes.stream() .filter(subtype -> subtype != Types.BOTTOM) |
