Interface Type

All Known Subinterfaces:
NamedType, RecordLikeType
All Known Implementing Classes:
BaseType, DataType, DummyType, FnType, ForallType, ListType, MultiType, ParameterizedType, PrimitiveType, ProgressiveRecordType, RecordType, TupleType, TypeVar

public interface Type
Type.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static class 
    Structural identifier of a type.
  • Method Summary

    Modifier and Type
    Method
    Description
    <R> R
    accept(TypeVisitor<R> typeVisitor)
     
    default Type
    arg(int i)
    Returns the ith type parameter.
    default boolean
    Whether this type is a function that can call an argument of given type.
    copy(TypeSystem typeSystem, UnaryOperator<Type> transform)
    Copies this type, applying a given transform to component types, and returning the original type if the component types are unchanged.
    default boolean
    Whether this is a collection type (list or bag).
    default boolean
    Whether this type has a small, fixed set of instances.
    default boolean
    Returns whether this type is progressive.
    key()
    Description of the type, e.g
    default String
    Key of the type.
    op()
    Type operator.
    default boolean
    Whether this type is the same as, or a specialization of, a given type.
    default Type
    substitute(TypeSystem typeSystem, List<? extends Type> types)
    Returns a copy of this type, specialized by substituting type parameters.
    default @Nullable Map<Integer,Type>
     
  • Method Details

    • key

      Type.Key key()
      Description of the type, e.g. "int", "int -> int", " NONE | SOME of 'a".
    • moniker

      default String moniker()
      Key of the type.

      Often the same as key(), but an exception is datatype. For example, datatype "'a option" has moniker and name "option" and description "NONE | SOME of 'a".

      Use the description if you are looking for a type that is structurally equivalent. Use the moniker to identify it when printing.

    • op

      Op op()
      Type operator.
    • arg

      default Type arg(int i)
      Returns the ith type parameter. Throws for types except ListType and DataType.
    • copy

      Type copy(TypeSystem typeSystem, UnaryOperator<Type> transform)
      Copies this type, applying a given transform to component types, and returning the original type if the component types are unchanged.
    • accept

      <R> R accept(TypeVisitor<R> typeVisitor)
    • substitute

      default Type substitute(TypeSystem typeSystem, List<? extends Type> types)
      Returns a copy of this type, specialized by substituting type parameters.
    • isProgressive

      default boolean isProgressive()
      Returns whether this type is progressive.

      Progressive types are records, but can have additional fields each time you look.

      The "file" value is an example.

    • isFinite

      default boolean isFinite()
      Whether this type has a small, fixed set of instances. True for bool, data types on finite types.
    • isCollection

      default boolean isCollection()
      Whether this is a collection type (list or bag).

      If a type is a collection type, arg(0) returns the element type.

    • canCallArgOf

      default boolean canCallArgOf(Type type)
      Whether this type is a function that can call an argument of given type.

      For example:

      • int is not a function and therefore results false for all argument types;
      • bool -> int can call arguments of type bool and 'a but not int or ('a, 'b);
      • forall 'a. 'a list -> bool can call arguments of type int list and string list list but not int option.
    • specializes

      default boolean specializes(Type type)
      Whether this type is the same as, or a specialization of, a given type.

      For example, bool specializes bool and 'a but does not specialize int or ('a, 'b).

    • unifyWith

      default @Nullable Map<Integer,Type> unifyWith(Type type)