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.
  • Method Details

    • simple

      static TypeDescriptor simple(PortType type)
      Creates a simple (non-parameterized) type descriptor.
    • typeVar

      static TypeDescriptor typeVar(String name)
      Creates a type variable that gets resolved from connected ports. Type variables are scoped per node: each node instance has its own bindings.
    • list

      static TypeDescriptor list(TypeDescriptor elementType)
      Creates a parameterized List type: List.
    • map

      static TypeDescriptor map(TypeDescriptor keyType, TypeDescriptor valueType)
      Creates a parameterized Map type: Map<keyType, valueType>.
    • listOf

      static TypeDescriptor listOf(PortType elementType)
      Convenience: List<Simple(elementType)>.
    • mapOf

      static TypeDescriptor mapOf(PortType keyType, PortType valueType)
      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

      TypeDescriptor resolve(Map<String, TypeDescriptor> bindings)
      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

      static boolean unify(TypeDescriptor a, TypeDescriptor b, Map<String, TypeDescriptor> bindings)

      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

      static Map<String, TypeDescriptor> newBindings()
      Creates a fresh bindings map for unification.