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

hlt.language.design.types

## Class DefinedType

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

- All Implemented Interfaces:
    Valuable, java.lang.Cloneable

      public class DefinedType
      extends TypeTerm

  This is the class of defined opaque types. This is a new type hiding the type that defines it. In other words, it acts as a wrapper for the defining type, and behaves as an entirely new type in that it will not unify against anything except itself or a type parameter.

  Look in `Tables` for the methods that will define a new opaque type (`DefineNewType(...)`).

  See Also:
    `TypeDefinition`, `Tables`

- - ### 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
    `DefinedType(java.lang.String name, Type definition)` Constructs a non-polymorphic defined type with the specified name and definition.
    `DefinedType(java.lang.String name, Type definition, java.util.AbstractList arguments)`
    `DefinedType(java.lang.String name, Type definition, Type[] arguments)` Constructs a polymorphic defined type with the specified name, definition, and type parameters.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Type` | `actualType()` Returns the value of this when this does not have a defining type; or that of its defining type otherwise.
    `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.
    `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.
    `Type` | `definition()`
    `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` | `isBoxedType()` This returns `true` iff this type has been marked as boxed (`true` by default - overridden by `TypeConstant`).
    `boolean` | `isPolymorphic()`
    `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.
    `Type` | `setBoxed(boolean flag)` With `true` (resp.
    `DefinedType` | `setDefinition(Type type)`
    `void` | `setTypeRefComponent(int n, Type type)` Sets the `n`-th undereferenced type component of this type to the specified type; throws a `NoSuchTypeComponentException` otherwise.
    `byte` | `sort()` This returns the runtime sort for this type (`OBJECT_SORT` by default - overridden by `TypeConstant`).
    `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)` Normally, a defined type can only unify against a type parameter or itself.

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

      `argument, arguments, arity, isEqualTo, isEqualTo, setArguments, setArguments, toString`

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

      `name, setName`

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

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

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

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

- - ### Constructor Detail

    - #### DefinedType

          public DefinedType(java.lang.String name,
                     Type definition)

      Constructs a non-polymorphic defined type with the specified name and definition.

    - #### DefinedType

          public DefinedType(java.lang.String name,
                     Type definition,
                     Type[] arguments)

      Constructs a polymorphic defined type with the specified name, definition, and type parameters.

    - #### DefinedType

          public DefinedType(java.lang.String name,
                     Type definition,
                     java.util.AbstractList arguments)

  - ### Method Detail

    - #### numberOfTypeComponents

          public int numberOfTypeComponents()

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

    - #### 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.
      Overrides:
        `typeRefComponent` in class `TypeTerm`
      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.
      Overrides:
        `setTypeRefComponent` in class `TypeTerm`
      Throws:
        `NoSuchTypeComponentException`

    - #### actualType

          public final Type actualType()

      Description copied from class: `Type`
      Returns the value of this when this does not have a defining type; or that of its defining type otherwise. This is overriden in `DefinedType`.
      Overrides:
        `actualType` in class `Type`

    - #### definition

          public final Type definition()

    - #### setDefinition

          public final DefinedType setDefinition(Type type)

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

    - #### isPolymorphic

          public final boolean isPolymorphic()

      Overrides:
        `isPolymorphic` in class `TypeTerm`

    - #### sort

          public final byte sort()

      Description copied from class: `Type`
      This returns the runtime sort for this type (`OBJECT_SORT` by default - overridden by `TypeConstant`).

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

      Overrides:
        `sort` in class `Type`

    - #### isBoxedType

          public final boolean isBoxedType()

      Description copied from class: `Type`
      This returns `true` iff this type has been marked as boxed (`true` by default - overridden by `TypeConstant`).

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

      Overrides:
        `isBoxedType` in class `Type`

    - #### setBoxed

          public final Type setBoxed(boolean flag)

      Description copied from class: `Type`
      With `true` (resp. `false`), this marks this type as boxed (resp., unboxed), if it is boxable. Does nothing by default.

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

      Overrides:
        `setBoxed` in class `Type`

    - #### unify

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

      Normally, a defined type can only unify against a type parameter or itself. However, if the type-checking mode allows it, opaque types whose actual type is a (named) tuple type will unify against similar raw tuple types.
      Overrides:
        `unify` in class `TypeTerm`
      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.
      Overrides:
        `unify` in class `TypeTerm`

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

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

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

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

    - #### instantiate

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

    - #### 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`).
      Overrides:
        `eqCode` in class `TypeTerm`