Class TypeVar

java.lang.Object
net.hydromatic.morel.type.TypeVar
All Implemented Interfaces:
Type

public class TypeVar extends Object implements Type
Type variable (e.g. 'a).
  • Field Details

    • ALPHAS

      private static final char[] ALPHAS
    • NAME_CACHE

      private static final com.google.common.cache.LoadingCache<Integer,String> NAME_CACHE
    • ordinal

      public final int ordinal
    • name

      private final String name
  • Constructor Details

    • TypeVar

      public TypeVar(int ordinal)
      Creates a type variable with a given ordinal.

      TypeVar.of(0) returns "'a"; TypeVar.of(1) returns "'b", etc.

  • Method Details

    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Returns a string for debugging.
      Overrides:
      toString in class Object
    • accept

      public <R> R accept(TypeVisitor<R> typeVisitor)
      Specified by:
      accept in interface Type
    • name

      static String name(int i)
      Generates a name for a type variable.

      0 → 'a, 1 → 'b, 26 → 'z, 27 → 'ba, 28 → 'bb, 675 → 'zz, 676 → 'baa, etc. (Think of it is a base 26 number, with "a" as 0, "z" as 25.)

    • key

      public Type.Key key()
      Description copied from interface: Type
      Description of the type, e.g. "int", "int -> int", "NONE | SOME of 'a".
      Specified by:
      key in interface Type
    • op

      public Op op()
      Description copied from interface: Type
      Type operator.
      Specified by:
      op in interface Type
    • copy

      public Type copy(TypeSystem typeSystem, UnaryOperator<Type> transform)
      Description copied from interface: Type
      Copies this type, applying a given transform to component types, and returning the original type if the component types are unchanged.
      Specified by:
      copy in interface Type
    • substitute

      public Type substitute(TypeSystem typeSystem, List<? extends Type> types)
      Description copied from interface: Type
      Returns a copy of this type, specialized by substituting type parameters.
      Specified by:
      substitute in interface Type