Class DataType

All Implemented Interfaces:
NamedType, Type

public class DataType extends ParameterizedType
Algebraic type.
  • Field Details

  • Constructor Details

    • DataType

      protected DataType(String name, String moniker, com.google.common.collect.ImmutableList<Type> arguments, com.google.common.collect.ImmutableMap<String,Type.Key> typeConstructors)
      Creates a DataType.

      Called only from TypeSystem.dataTypes(List).

      If the typeSystem argument is specified, canonizes the types inside type-constructors. This also allows temporary types (necessary while creating self-referential data types) to be replaced with real DataType instances.

      During replacement, if a type matches placeholderType it is replaced with this. This allows cyclic graphs to be copied.

  • Method Details

    • key

      public Keys.DataTypeKey key()
      Description copied from interface: Type
      Description of the type, e.g. "int", "int -> int", " NONE | SOME of 'a".
    • arg

      public Type arg(int i)
      Description copied from interface: Type
      Returns the ith type parameter. Throws for types except ListType and DataType.
    • isCollection

      public boolean isCollection()
      Description copied from interface: Type
      Whether this is a collection type (list or bag).

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

    • accept

      public <R> R accept(TypeVisitor<R> typeVisitor)
    • typeConstructors

      public Map<String,Type> typeConstructors(TypeSystem typeSystem)
    • copy

      public DataType 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.
    • describe

      public StringBuilder describe(StringBuilder buf)
      Writes out the definition of the datatype. For example,
      
       datatype ('a,'b) tree =
           Empty
         | Node of ('a,'b) tree * 'b * 'a * ('a,'b) tree
       
    • specializes

      public boolean specializes(Type type)
      Description copied from interface: 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).