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

hlt.language.design.types

## Class NamedTupleType

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

- All Implemented Interfaces:
    Valuable

      public class NamedTupleType
      extends TupleType

  This is the type of tuples whose components are identified by field names. It derives from `TupleType`, and in addition keeps an array of `TupleFieldName`s recording the names. The reason for using `TupleFieldName`s rather than `String`s is so that the array of field names may be sorted lexicographically for the purpose of normalizing all named tuples and named tuple types, while recording their original indices for displaying components in their "original" order. Note that this notion is rather fuzzy as it corresponds to the ordering of components found by the constructor (which is meant to be used by a parser) and can only be that of a specific written named tuple (type) occurrence. Thus, this order may only be one among many if distinct occurrences of this type, or tuples of this type, are written using differring orders of components. Nevertheless, for consistently written tuples, the components will be displayed in the expected order.

- - ### Field Summary

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

      `EMPTY`

    - ### 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
    `NamedTupleType(java.util.AbstractList components, java.util.AbstractList names)`
    `NamedTupleType(Type[] components, TupleFieldName[] fields)` This trusts the component types to be non void.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `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.
    `TupleFieldName` | `field(int n)` Returns the field name originally in the specified position; `null` if position is not legal.
    `int` | `fieldPosition(int n)` Returns the position of the field whose original index is `n-1`.
    `TupleFieldName[]` | `fields()`
    `java.lang.String` | `fieldSet()`
    `int[]` | `index()`
    `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.
    `byte` | `kind()` This returns the value identifying what kind of type this is.
    `int` | `position(java.lang.String name)` Returns the position of the field whose name is `name`.
    `java.lang.String` | `toString()`
    `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.TupleType

      `checkOccurrence, component, components, dimension, eqCode, flatten, getParameters, instantiate, newTupleType, newTupleType, numberOfTypeComponents, setTypeRefComponent, typeRefComponent`

    - ### 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, isPolymorphic, 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

    - #### NamedTupleType

          public NamedTupleType(Type[] components,
                        TupleFieldName[] fields)

      This trusts the component types to be non void. It is public (even though it is not meant for public use) because it is called from `NamedTuple` and Java's access restriction is too coarse to handle limited visibility across packages.

    - #### NamedTupleType

          public NamedTupleType(java.util.AbstractList components,
                        java.util.AbstractList names)

  - ### Method Detail

    - #### fields

          public final TupleFieldName[] fields()

    - #### index

          public final int[] index()

    - #### fieldSet

          public final java.lang.String fieldSet()

    - #### position

          public final int position(java.lang.String name)

      Returns the position of the field whose name is `name`. NB: Positions are counted starting from 1, not 0.

    - #### field

          public final TupleFieldName field(int n)

      Returns the field name originally in the specified position; `null` if position is not legal.

    - #### fieldPosition

          public final int fieldPosition(int n)

      Returns the position of the field whose original index is `n-1`. NB: Positions are counted starting from 1, not 0.

    - #### kind

          public final byte kind()

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

    - #### unify

          public final 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`.
      Overrides:
        `unify` in class `TupleType`
      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.
      Overrides:
        `unify` in class `TupleType`

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

    - #### isEqualTo

          public final boolean isEqualTo(Type type)

      Description copied from class: `Type`
      Returns true iff this type is structurally isomorphic to the specified type. Two type parameters will be considered equal only if they are the same object (i.e., equal pointers).
      Overrides:
        `isEqualTo` in class `TupleType`

    - #### isEqualTo

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

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

    - #### toString

          public final java.lang.String toString()

      Overrides:
        `toString` in class `TupleType`