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

hlt.language.design.types

## Class TypeParameter

- java.lang.Object
- - hlt.language.design.types.Type
  - - hlt.language.design.types.StaticType
    - - hlt.language.design.types.TypeParameter

- All Implemented Interfaces:
    Bindable, Valuable

      public class TypeParameter
      extends StaticType
      implements Bindable

- - ### 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
    `TypeParameter()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `addResiduation(ResiduatedGoal residuation, int refCount)` Installs the specified residuation to be triggered by this type parameter, saving the specified reference count to reinstate for the residuation upon unbinding this type parameter.
    `boolean` | `bind(Valuable value)` Binds this bindable to the given valuable.
    `boolean` | `bind(Valuable valuable, GoalProver prover)` Binds this type parameter to the given valuable in the context of the given prover.
    `void` | `checkOccurrence(TypeParameter parameter, Type context, TypeChecker typeChecker)` Throws a `FailedUnificationException` if the specified type parameter occurs in this type.
    `Type` | `copy()` This returns this type parameter unchanged.
    `Type` | `copy(java.util.HashMap parameters)` Returns a copy of this `TypeParameter` as per the renaming given by the specified `HashMap`.
    `void` | `curry(int depth, TypeChecker typeChecker)` If this this a function type, transforms the type by splitting the domains at the specified depth, and records the old form in the appropriate trail of the specified type-checker for undoing purposes.
    `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 `==`).
    `boolean` | `equals(java.lang.Object object)` Returns true iff this type parameter is the given object.
    `Type` | `findValue()` This returns the type value this is bound to and side-effects the binding chains by shortening them (i.e., like the FIND operation of the "UNION/FIND" algorithm.
    `Type` | `flatten()` Flattens this type parameter's value 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 the instance value given for this TypeParameter by the specified substitution, or this if none is given.
    `boolean` | `isBound()` Returns `true` iff this bindable is bound.
    `boolean` | `isEqualTo(Type type)` Returns true iff this type parameter is the given one.
    `boolean` | `isEqualTo(Type type, java.util.HashMap parameters)` Returns true iff this type is parameter is equal to the given one under the renaming of type parameters specified by the given HashMap.
    `boolean` | `isPolymorphic()`
    `boolean` | `isUnbound()` Returns `true` iff this bindable is unbound.
    `byte` | `kind()` This returns the value identifying what kind of type this is.
    `int` | `numberOfTypeComponents()` Returns the number of type components making up this type.
    `int` | `parameterIndex()` This returns this parameter's index in the header array of a type's quantifies string where this appears.
    `ObjectToIntMap` | `residuations()`
    `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.
    `void` | `unbind()` This unbinds this type parameter and resets the reference counts for all residuations this has a trigger link with, if any.
    `boolean` | `unify(Type type)` NB: does not perform the "occurs-check" test.
    `void` | `unify(Type type, TypeChecker typeChecker)` Unifies this type parameter with the given type in the context of the given type-checker.
    `Type` | `value()` This method acts as a type parameter dereferencing for possibly bound type parameters.

    - ### 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, getParameters, getValue, INT, is, isBag, isBoolean, isBoxedType, isChar, isCollection, isGlobalUnsafe, isInt, isList, isPrimitive, isReal, isSet, isString, isVoid, kindString, rank, REAL, resetNames, setBoxed, shadowType, sort, standardize, toFullString, toQuantifiedString, toQuantifiedString, typeComponent, unwrapper, wrapper`

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

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

    - ### Methods inherited from interface hlt.language.design.types.Valuable

      `getValue`

- - ### Constructor Detail

    - #### TypeParameter

          public TypeParameter()

  - ### Method Detail

    - #### residuations

          public final ObjectToIntMap residuations()

    - #### numberOfTypeComponents

          public final 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 final 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 final 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`

    - #### kind

          public final byte kind()

      Description copied from class: `Type`
      This returns the value identifying what kind of type this is.
      Specified by:
        `kind` in class `Type`

    - #### value

          public final Type value()

      This method acts as a type parameter dereferencing for possibly bound type parameters. Type parameters act as logical variable in Prolog and may get bound by type unification during type checking/inference.
      Overrides:
        `value` in class `Type`

    - #### findValue

          public final Type findValue()

      This returns the type value this is bound to and side-effects the binding chains by shortening them (i.e., like the FIND operation of the "UNION/FIND" algorithm. In other words, it returns the same value as the `value()` method, but with a side-effect of setting its `_value` field to the type it is bound to (which is itself if unbound)
      Overrides:
        `findValue` in class `Type`

    - #### isBound

          public final boolean isBound()

      Description copied from interface: `Bindable`
      Returns `true` iff this bindable is bound.
      Specified by:
        `isBound` in interface `Bindable`

    - #### isUnbound

          public final boolean isUnbound()

      Description copied from interface: `Bindable`
      Returns `true` iff this bindable is unbound.
      Specified by:
        `isUnbound` in interface `Bindable`

    - #### bind

          public final boolean bind(Valuable valuable,
                     GoalProver prover)

      Binds this type parameter to the given valuable in the context of the given prover. This binding is appropriately trailed in the contextual prover for undoing purposes. Returns `true`.
      Specified by:
        `bind` in interface `Bindable`

    - #### bind

          public final boolean bind(Valuable value)

      Description copied from interface: `Bindable`
      Binds this bindable to the given valuable.
      Specified by:
        `bind` in interface `Bindable`

    - #### unbind

          public final void unbind()

      This unbinds this type parameter and resets the reference counts for all residuations this has a trigger link with, if any.
      Specified by:
        `unbind` in interface `Bindable`

    - #### addResiduation

          public final boolean addResiduation(ResiduatedGoal residuation,
                               int refCount)

      Installs the specified residuation to be triggered by this type parameter, saving the specified reference count to reinstate for the residuation upon unbinding this type parameter.

    - #### getParameters

          public final 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`

    - #### isPolymorphic

          public final boolean isPolymorphic()

      Overrides:
        `isPolymorphic` in class `Type`

    - #### curry

          public final void curry(int depth,
                   TypeChecker typeChecker)

      Description copied from class: `Type`
      If this this a function type, transforms the type by splitting the domains at the specified depth, and records the old form in the appropriate trail of the specified type-checker for undoing purposes. For example, currying A[1],...,A[n]n -> A at depth k (A[k+1],...,A[n] -> A). If this type is a type parameter, this will curry its value if any. Otherwise, does nothing.

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

      Overrides:
        `curry` in class `Type`

    - #### flatten

          public final Type flatten()

      Flattens this type parameter's value by uncurrying all the domains of all function types that occur in it. This is the canonical for used for all types of defined symbols.
      Overrides:
        `flatten` in class `Type`

    - #### parameterIndex

          public final int parameterIndex()

      This returns this parameter's index in the header array of a type's quantifies string where this appears.

    - #### copy

          public final Type copy(java.util.HashMap parameters)

      Returns a copy of this `TypeParameter` as per the renaming given by the specified `HashMap`. If this `TypeParameter` is already renamed by the parameters, then the renamed copy is returned. Otherwise, a fresh `TypeParameter` is entered as a renaming for it in the parameters and returned.
      Overrides:
        `copy` in class `Type`

    - #### instantiate

          public final Type instantiate(java.util.HashMap substitution)

      Returns the instance value given for this TypeParameter by the specified substitution, or this if none is given.
      Overrides:
        `instantiate` in class `Type`

    - #### copy

          public final Type copy()

      This returns this type parameter unchanged. Note the difference of this method and its namesake `copy(HashMap)` taking a renaming table, and which returns a distinct copy. This difference is very important as an unquantified `TypeParameter` must be regarded as a constant type that may be shared in a context. In the absence of this context (provided by a renaming table in the method `copy(HashMap)`), it must be assumed that the renaming is the identity to capture consistently several occurrences.
      Overrides:
        `copy` in class `Type`

    - #### unify

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

      Unifies this type parameter with the given type in the context of the given type-checker. If this occurs in the specified type, unification fails by throwing a FailedUnificationException. Otherwise this get bound to the specified type. This binding is appropriately trailed in the contextual type-checker for undoing purposes.
      Specified by:
        `unify` in class `Type`
      Throws:
        `FailedUnificationException`

    - #### unify

          public final boolean unify(Type type)

      NB: does not perform the "occurs-check" test.
      Specified by:
        `unify` in class `Type`

    - #### checkOccurrence

          public final 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`

    - #### eqCode

          public final 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`).
      Specified by:
        `eqCode` in class `Type`

    - #### equals

          public final boolean equals(java.lang.Object object)

      Returns true iff this type parameter is the given object.
      Overrides:
        `equals` in class `Type`

    - #### isEqualTo

          public final boolean isEqualTo(Type type)

      Returns true iff this type parameter is the given one.
      Specified by:
        `isEqualTo` in class `Type`

    - #### isEqualTo

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

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

    - #### toString

          public final java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`