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

hlt.language.design.types

## Class ArrayType

- java.lang.Object
- - hlt.language.design.types.Type
  - - hlt.language.design.types.StaticType
    - - hlt.language.design.types.ConstructedType
      - - hlt.language.design.types.ArrayType

- All Implemented Interfaces:
    Valuable

      public class ArrayType
      extends ConstructedType

  This class denotes the type of arrays. Types of this kind consist of unidimensional array types whose elements are of any base type (including arrays - thus enabling multidimensional arrays - and type parameters - thus enabling polymorphic arrays).
  Version:
    Last modified on Wed Jun 20 14:29:51 2012 by hak
  Author:
    Hassan Aït-Kaci
  Copyright:
    © by the author

- - ### 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
    `ArrayType()` Constructs a polymorphic array type; i.e., one whose base type is a type parameter.
    `ArrayType(Type baseType)` Constructs an array type with the specified base type.
    `ArrayType(Type baseType, Type indexSetType)` Constructs an array type with the specified base type and index-set type.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Type` | `baseType()` Returns the base type's value.
    `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` | `dimension()` Returns the number of dimensions of this array type; i.e., the number of indices needed to dereference to the innermost component.
    `Type` | `dimension(int n)` Returns the type of the `n`-th dimension, counting from `0`.
    `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` | `indexSetType()` Returns the index-set type's value.
    `Type` | `indexType()` Returns the index type's value; i.e., this is the type that an actual index will have.
    `Type` | `innermostType()` Returns the innermost type.
    `Type` | `innerType(int depth)` Returns the inner type up to depth `n`.
    `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` | `isMap()` Returns `true` iff this array type is that of an indexed map.
    `boolean` | `isPolymorphic()` Returns `true` iff this array type's base type is polymorphic.
    `byte` | `kind()` Returns the constant identifying array types; i.e., `Type.ARRAY`.
    `int` | `numberOfTypeComponents()` Returns the number of type components making up this type.
    `Type` | `projection(int n)` Returns the type obtained after projecting out the first `n` indices.
    `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)` Unifies this array type against the specifed type in the context of the given type checker.

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

      `actualType, array, array, 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, 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

    - #### ArrayType

          public ArrayType()

      Constructs a polymorphic array type; i.e., one whose base type is a type parameter.

    - #### ArrayType

          public ArrayType(Type baseType)

      Constructs an array type with the specified base type.

    - #### ArrayType

          public ArrayType(Type baseType,
                   Type indexSetType)

      Constructs an array type with the specified base type and index-set type.

  - ### Method Detail

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

      Returns the constant identifying array types; i.e., `Type.ARRAY`.
      Specified by:
        `kind` in class `Type`

    - #### baseType

          public final Type baseType()

      Returns the base type's value. This is the type binding of the array's components when the array is viewed as a unidimensional vector; e.g., for array type instantiated to `int[][]`, this returns `int[]`.
      Overrides:
        `baseType` in class `Type`

    - #### indexSetType

          public final Type indexSetType()

      Returns the index-set type's value.

    - #### isMap

          public final boolean isMap()

      Returns `true` iff this array type is that of an indexed map.

    - #### indexType

          public final Type indexType()

      Returns the index type's value; i.e., this is the type that an actual index will have. NB: This assumes that the index-set type is of correct kind - which is guaranteed when type-checking array slots where this method is called.

    - #### isPolymorphic

          public final boolean isPolymorphic()

      Returns `true` iff this array type's base type is polymorphic. Note that this lets the index set type be polymorphic - because it can never be an unbound type parameter and if it is a set type, its base type does not matter.
      Overrides:
        `isPolymorphic` in class `Type`

    - #### innermostType

          public final Type innermostType()

      Returns the innermost type. This is the type of the array's innermost elements; e.g., for an array type instantiated to `int[][]`, this returns `int`.

    - #### innerType

          public final Type innerType(int depth)

      Returns the inner type up to depth `n`. If `n=0`, it is this type; if `n=1`, it is the base type; if `n=2` and the base type is an array type, this is the base type's base type; etc.. For example, for an array type instantiated to `int[][][]`, this returns `int[][][]` for `n=0`, `int[][]` for `n=1`, `int[]` for `n=2`, and `int` for `n=3`.

    - #### dimension

          public final int dimension()

      Returns the number of dimensions of this array type; i.e., the number of indices needed to dereference to the innermost component. For example, the dimension of `int[][][]` is `3`.

    - #### dimension

          public final Type dimension(int n)

      Returns the type of the `n`-th dimension, counting from `0`. For example, for array type `int[int][{string}][int..int]`, `dimension(1)` is `{string}`. If the specified number is more than the number of actual dimensions, this returns `null`.

    - #### projection

          public final Type projection(int n)

      Returns the type obtained after projecting out the first `n` indices. For example, `projection(2)` of array type `int[int..int][int][{char}][int]` is `int[{char}][int]`. If the specified number is greater than the number of actual dimensions, this returns `null`.

    - #### flatten

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

    - #### copy

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

    - #### unify

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

      Unifies this array type against the specifed type in the context of the given type checker. Note that the advantage of representing array types systematically as one-dimensional vectors allows for unifying array types of different dimensions when the one of lesser dimension is polymorphic (i.e., when its base type is a type parameter).
      Specified by:
        `unify` in class `Type`
      Throws:
        `FailedUnificationException`

    - #### unify

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

    - #### 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`

    - #### 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`

    - #### 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`

    - #### toString

          public final java.lang.String toString()

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