Interface TypeDescriptor
- All Known Implementing Classes:
TypeDescriptor.Parameterized, TypeDescriptor.Simple, TypeDescriptor.TypeVariable
public sealed interface TypeDescriptor
permits TypeDescriptor.Simple, TypeDescriptor.Parameterized, TypeDescriptor.TypeVariable
A recursive type descriptor that supports generic/parameterized types.
Used on port definitions to express types like List, Map<String, Number>,
or type variables like T that get resolved based on connections.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordA parameterized type like Listor Map<K, V>. static final recordA simple, non-parameterized type (e.g., NUMBER, STRING, BOT).static final recordA type variable that gets bound during type inference. -
Method Summary
Modifier and TypeMethodDescriptionbaseType()Returns the base PortType for backward compatibility.Returns a human-readable representation like "List" or "T". booleanChecks whether this descriptor contains any type variables.static TypeDescriptorlist(TypeDescriptor elementType) Creates a parameterized List type: List. static TypeDescriptorConvenience: List<Simple(elementType)>.static TypeDescriptormap(TypeDescriptor keyType, TypeDescriptor valueType) Creates a parameterized Map type: Map<keyType, valueType>.static TypeDescriptorConvenience: Map<Simple(keyType), Simple(valueType)>.static Map<String, TypeDescriptor> Creates a fresh bindings map for unification.resolve(Map<String, TypeDescriptor> bindings) Resolves type variables using the given bindings.static TypeDescriptorCreates a simple (non-parameterized) type descriptor.static TypeDescriptorCreates a type variable that gets resolved from connected ports.static booleanunify(TypeDescriptor a, TypeDescriptor b, Map<String, TypeDescriptor> bindings) Attempts to unify two type descriptors, updating bindings for type variables.
-
Method Details
-
simple
Creates a simple (non-parameterized) type descriptor. -
typeVar
Creates a type variable that gets resolved from connected ports. Type variables are scoped per node: each node instance has its own bindings. -
list
Creates a parameterized List type: List. -
map
Creates a parameterized Map type: Map<keyType, valueType>. -
listOf
Convenience: List<Simple(elementType)>. -
mapOf
Convenience: Map<Simple(keyType), Simple(valueType)>. -
baseType
PortType baseType()Returns the base PortType for backward compatibility. Simple returns its type, Parameterized returns its base, TypeVariable returns ANY. -
displayString
String displayString()Returns a human-readable representation like "List" or "T". -
resolve
Resolves type variables using the given bindings. Returns a new TypeDescriptor with all known variables replaced. -
hasTypeVariables
boolean hasTypeVariables()Checks whether this descriptor contains any type variables. -
unify
Attempts to unify two type descriptors, updating bindings for type variables. Returns true if unification succeeds, false if the types are incompatible.
Unification rules:
- TypeVariable unifies with anything (binds the variable)
- Simple(ANY) unifies with anything
- Simple(A) unifies with Simple(B) if A == B or compatible via TypeCompatibility
- Parameterized(base, params) unifies with Parameterized(base2, params2) if base == base2 and all params unify pairwise
-
newBindings
Creates a fresh bindings map for unification.
-