TypeTerm (API documentation of hlt.language packages)
Date: 2013-01-30

hlt.language.design.types

## Class TypeTerm

- java.lang.Object
- - hlt.language.design.types.Type
  - - hlt.language.design.types.StaticType
    - - hlt.language.design.types.NamedType
      - - hlt.language.design.types.TypeTerm

- All Implemented Interfaces:
    Valuable, java.lang.Cloneable
  Direct Known Subclasses:
    ClassType, DefinedType

      public abstract class TypeTerm
      extends NamedType
      implements java.lang.Cloneable

- - ### Field Summary

    - ### Fields inherited from class hlt.language.design.types.Type

      `ARRAY, BAG, BOOLEAN, BOXABLE, CHAR, CLASS, COLLECTION, CONSTANT, DEFINED, FUNCTION, INT, INT_RANGE, INT_SORT, LIST, NAMED_TUPLE, OBJECT_SORT, PARAMETER, REAL, REAL_RANGE, REAL_SORT, SET, STRING, TUPLE, VOID, VOID_SORT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TypeTerm()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Type` | `argument(int i)`
    `Type[]` | `arguments()`
    `int` | `arity()`
    `void` | `checkOccurrence(TypeParameter parameter, Type context, TypeChecker typeChecker)` Throws a `FailedUnificationException` if the specified type parameter occurs in this type.
    `Type` | `copy(java.util.HashMap parameters)` Returns a copy of this type with a consistent renaming of all free type parameters, and identyfing bound type parameters with their values.
    `int` | `eqCode()` Returns a hash code for this type - the reason for using the name `eqCode` (rather than overriding `hashCode`), is that it is important to preserve the implementation of `java.lang.Object.hashCode` for type parameters (to be compatible with `==`).
    `Type` | `flatten()` Returns a flattened form of this type by uncurrying all the domains of all function types that occur in it.
    `java.util.HashSet` | `getParameters(java.util.HashSet set)` Returns the specified set augmented with all the unbound type parameters that occur in this type.
    `Type` | `instantiate(java.util.HashMap substitution)` Returns a copy of this type with all free type parameters bound as per the specified type substitution.
    `boolean` | `isEqualTo(Type type)` Returns true iff this type is structurally isomorphic to the specified type.
    `boolean` | `isEqualTo(Type type, java.util.HashMap parameters)` Returns `true` iff this type is structurally isomorphic to the specified type, under the renaming of type parameters specified by the given HashMap.
    `boolean` | `isPolymorphic()`
    `int` | `numberOfTypeComponents()` Returns the number of type components making up this type.
    `TypeTerm` | `setArguments(java.util.AbstractList arguments)`
    `TypeTerm` | `setArguments(Type[] arguments)`
    `void` | `setTypeRefComponent(int n, Type type)` Sets the `n`-th undereferenced type component of this type to the specified type; throws a `NoSuchTypeComponentException` otherwise.
    `java.lang.String` | `toString()`
    `Type` | `typeRefComponent(int n)` Returns the `n`-th undereferenced type component in this type, if any; throws a `NoSuchTypeComponentException` otherwise.
    `boolean` | `unify(Type type)` This unifies this type with the specified type with no possibility of undoing any effects.
    `void` | `unify(Type type, TypeChecker typeChecker)` This unifies this type with the specified type in the context of the specified `TypeChecker`.

    - ### Methods inherited from class hlt.language.design.types.NamedType

      `name, setName`

    - ### Methods inherited from class hlt.language.design.types.Type

      `actualType, array, array, baseType, baseTypeRef, BOOLEAN, BOXED_BOOLEAN, BOXED_CHAR, BOXED_INT, BOXED_REAL, boxSort, CHAR, copy, curry, equals, findValue, getParameters, getValue, INT, is, isBag, isBoolean, isBoxedType, isChar, isCollection, isGlobalUnsafe, isInt, isList, isPrimitive, isReal, isSet, isString, isVoid, kind, kindString, rank, REAL, resetNames, setBoxed, shadowType, sort, standardize, toFullString, toQuantifiedString, toQuantifiedString, typeComponent, unwrapper, value, wrapper`

    - ### Methods inherited from class java.lang.Object

      `getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### TypeTerm

          public TypeTerm()

  - ### Method Detail

    - #### numberOfTypeComponents

          public int numberOfTypeComponents()

      Description copied from class: `Type`
      Returns the number of type components making up this type.
      Specified by:
        `numberOfTypeComponents` in class `Type`

    - #### typeRefComponent

          public Type typeRefComponent(int n)
                                throws NoSuchTypeComponentException

      Description copied from class: `Type`
      Returns the `n`-th undereferenced type component in this type, if any; throws a `NoSuchTypeComponentException` otherwise.
      Specified by:
        `typeRefComponent` in class `Type`
      Throws:
        `NoSuchTypeComponentException`

    - #### setTypeRefComponent

          public void setTypeRefComponent(int n,
                                 Type type)
                                   throws NoSuchTypeComponentException

      Description copied from class: `Type`
      Sets the `n`-th undereferenced type component of this type to the specified type; throws a `NoSuchTypeComponentException` otherwise.
      Specified by:
        `setTypeRefComponent` in class `Type`
      Throws:
        `NoSuchTypeComponentException`

    - #### arguments

          public final Type[] arguments()

    - #### argument

          public final Type argument(int i)

    - #### arity

          public final int arity()

    - #### setArguments

          public final TypeTerm setArguments(java.util.AbstractList arguments)

    - #### setArguments

          public final TypeTerm setArguments(Type[] arguments)

    - #### flatten

          public Type flatten()

      Description copied from class: `Type`
      Returns a flattened form of this type by uncurrying all the domains of all function types that occur in it. It also trims all binding chains of type parameters that may occur in it. The form returned is the canonical form used for all types of defined symbols and is assumed for type equality tests to work.

      N.B.: The following definition specifies only the default behavior for this method. Specific subclasses are generally expected to override this method.

      Overrides:
        `flatten` in class `Type`

    - #### isPolymorphic

          public boolean isPolymorphic()

      Overrides:
        `isPolymorphic` in class `Type`

    - #### copy

          public Type copy(java.util.HashMap parameters)

      Description copied from class: `Type`
      Returns a copy of this type with a consistent renaming of all free type parameters, and identyfing bound type parameters with their values.

      N.B.: The following definition specifies only the default behavior for this method. Specific subclasses are generally expected to override this method.

      Overrides:
        `copy` in class `Type`

    - #### instantiate

          public Type instantiate(java.util.HashMap substitution)

      Description copied from class: `Type`
      Returns a copy of this type with all free type parameters bound as per the specified type substitution.

      N.B.: The following definition specifies only the default behavior for this method. Specific subclasses are generally expected to override this method.

      Overrides:
        `instantiate` in class `Type`

    - #### eqCode

          public int eqCode()

      Description copied from class: `Type`
      Returns a hash code for this type - the reason for using the name `eqCode` (rather than overriding `hashCode`), is that it is important to preserve the implementation of `java.lang.Object.hashCode` for type parameters (to be compatible with `==`). All we require with this new code is that it be compatible with type equality as defined by `isEqualTo` - and it is! Incidentally, the same reason goes for preserving `equals` for type parameters to be compatible with `==` - and it is (see `TypeParameter`).
      Overrides:
        `eqCode` in class `NamedType`

    - #### isEqualTo

          public final boolean isEqualTo(Type type)

      Returns true iff this type is structurally isomorphic to the specified type. Type parameters that occur in all types will be considered equal only if they are identical objects (i.e., same pointers).
      Specified by:
        `isEqualTo` in class `Type`

    - #### isEqualTo

          public final boolean isEqualTo(Type type,
                          java.util.HashMap parameters)

      Returns `true` iff this type is structurally isomorphic to the specified type, under the renaming of type parameters specified by the given HashMap.
      Specified by:
        `isEqualTo` in class `Type`

    - #### unify

          public void unify(Type type,
                   TypeChecker typeChecker)
                     throws FailedUnificationException

      Description copied from class: `Type`
      This unifies this type with the specified type in the context of the specified `TypeChecker`.
      Specified by:
        `unify` in class `Type`
      Throws:
        `FailedUnificationException`

    - #### unify

          public boolean unify(Type type)

      Description copied from class: `Type`
      This unifies this type with the specified type with no possibility of undoing any effects. This method is meant to be used on types that are fresh copies independent of any type-checker because it will side-effect the structures it traverses. It returns `true` iff unification succeeds. NB: This method does not perform the "occurs-check" test.
      Specified by:
        `unify` in class `Type`

    - #### checkOccurrence

          public void checkOccurrence(TypeParameter parameter,
                             Type context,
                             TypeChecker typeChecker)
                               throws FailedUnificationException

      Description copied from class: `Type`
      Throws a `FailedUnificationException` if the specified type parameter occurs in this type. The type `context` is the outermost type enclosing this.

      N.B.: The following definition specifies only the default behavior for this method. Specific subclasses are generally expected to override this method.

      Overrides:
        `checkOccurrence` in class `Type`
      Throws:
        `FailedUnificationException`

    - #### getParameters

          public java.util.HashSet getParameters(java.util.HashSet set)

      Description copied from class: `Type`
      Returns the specified set augmented with all the unbound type parameters that occur in this type.
      Overrides:
        `getParameters` in class `Type`

    - #### toString

          public final java.lang.String toString()

      Overrides:
        `toString` in class `NamedType`