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

hlt.language.design.types

## Class FunctionType

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

- All Implemented Interfaces:
    Valuable

      public class FunctionType
      extends ConstructedType

- - ### 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
    `FunctionType()`
    `FunctionType(java.util.AbstractList domains, Type range)`
    `FunctionType(int arity)`
    `FunctionType(int arity, Type range)`
    `FunctionType(Type[] domains, Type range)`
    `FunctionType(Type[] domains, Type range, hlt.language.design.types.BoxingMask mask)`
    `FunctionType(Type[] domains, Type range, FunctionType copy)`
    `FunctionType(Type domain, Type range)`
    `FunctionType(Type domain1, Type domain2, Type range)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `argumentSortsDisagree(FunctionType actualType, int i)`
    `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 FunctionType as per the renaming given by the specified HashMap.
    `void` | `curry(int depth)` Does the same as the version above, except that it is a one-time destructive procedure (similar to the two versions of the unify method).
    `void` | `curry(int depth, TypeChecker typeChecker)` Transforms this function type by splitting its domains at the specified depth, and records the old form in the appropriate trail of the specified type-checker for undoing purposes.
    `Type` | `curryedRange()` If this function type is of the form `D1,...,Dn -> R`, this method returns `D2,...,Dn -> R` if `n` > 0, or `R` if `n` = 0.
    `Type` | `domain(int i)` Returns the dereferenced value of the i-th domain type.
    `boolean` | `domainIsBoxed(int i)`
    `Type` | `domainRef(int i)` Returns the undereferenced i-th domain type.
    `Type[]` | `domains()` Returns list of domain types.
    `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()` Flattens this function type and all function types that occur in it by uncurrying all the domains.
    `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 an instantiated copy of this function type as per the specified 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()`
    `byte` | `kind()` Returns the constant that identifies this as a function type.
    `hlt.language.design.types.BoxingMask` | `mask()` Returns the dereferenced boxing mask.
    `hlt.language.design.types.BoxingMask` | `maskRef()` Returns the undereferenced boxing mask.
    `java.lang.String` | `maskString()`
    `boolean` | `mustUnwrapArgument(FunctionType actualType, int i)`
    `boolean` | `mustUnwrapResult(FunctionType actualType)`
    `boolean` | `mustWrapArgument(FunctionType actualType, int i)`
    `boolean` | `mustWrapResult(FunctionType actualType)`
    `boolean` | `noCurrying()`
    `int` | `numberOfTypeComponents()` Returns the number of type components making up this type.
    `Type` | `range()` Returns the dereferenced value of the range type.
    `boolean` | `rangeIsBoxed()`
    `Type` | `rangeRef()` Returns the undereferenced range type.
    `boolean` | `resultSortsDisagree(FunctionType actualType)`
    `void` | `setDomainBox(int i)`
    `void` | `setDomains(Type[] domains)` Sets the list of domain types to the specified list of types.
    `FunctionType` | `setNoCurrying()`
    `FunctionType` | `setNoCurrying(boolean flag)`
    `void` | `setRange(Type range)` Sets the range type to the specified type.
    `void` | `setRangeBox()`
    `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()` Returns a string form for a function type.
    `boolean` | `trueDomainIsBoxed(int i)`
    `boolean` | `trueRangeIsBoxed()`
    `Type` | `typeRefComponent(int n)` Returns the `n`-th undereferenced type component in this type, if any; throws a `NoSuchTypeComponentException` otherwise.
    `FunctionType` | `uncurry()` When this function type is of the form `A[1],...,A[n] -> (B[1],...,B[m] -> R)`, this returns the function type `A[1],...,A[n],B[1],...,B[m] -> R`, making sure to preserves boxing masks appropriately.
    `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 function type with the given type in the context of the given type-checker.
    `void` | `unsetDomainBox(int i)`
    `void` | `unsetRangeBox()`

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

    - #### FunctionType

          public FunctionType()

    - #### FunctionType

          public FunctionType(int arity)

    - #### FunctionType

          public FunctionType(int arity,
                      Type range)

    - #### FunctionType

          public FunctionType(Type domain,
                      Type range)

    - #### FunctionType

          public FunctionType(Type domain1,
                      Type domain2,
                      Type range)

    - #### FunctionType

          public FunctionType(Type[] domains,
                      Type range)

    - #### FunctionType

          public FunctionType(Type[] domains,
                      Type range,
                      hlt.language.design.types.BoxingMask mask)

    - #### FunctionType

          public FunctionType(Type[] domains,
                      Type range,
                      FunctionType copy)

    - #### FunctionType

          public FunctionType(java.util.AbstractList domains,
                      Type range)

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

      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`

    - #### setTypeRefComponent

          public final void setTypeRefComponent(int n,
                                 Type type)

      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`

    - #### noCurrying

          public final boolean noCurrying()

    - #### setNoCurrying

          public final FunctionType setNoCurrying()

    - #### setNoCurrying

          public final FunctionType setNoCurrying(boolean flag)

    - #### kind

          public final byte kind()

      Returns the constant that identifies this as a function type.
      Specified by:
        `kind` in class `Type`

    - #### domains

          public final Type[] domains()

      Returns list of domain types.

    - #### maskRef

          public final hlt.language.design.types.BoxingMask maskRef()

      Returns the undereferenced boxing mask.

    - #### mask

          public final hlt.language.design.types.BoxingMask mask()

      Returns the dereferenced boxing mask.

    - #### setDomains

          public final void setDomains(Type[] domains)

      Sets the list of domain types to the specified list of types.

    - #### setRange

          public final void setRange(Type range)

      Sets the range type to the specified type.

    - #### domain

          public final Type domain(int i)

      Returns the dereferenced value of the i-th domain type.

    - #### domainRef

          public final Type domainRef(int i)

      Returns the undereferenced i-th domain type.

    - #### rangeRef

          public final Type rangeRef()

      Returns the undereferenced range type.

    - #### range

          public final Type range()

      Returns the dereferenced value of the range type.

    - #### isPolymorphic

          public final boolean isPolymorphic()

      Overrides:
        `isPolymorphic` in class `Type`

    - #### curryedRange

          public final Type curryedRange()

      If this function type is of the form `D1,...,Dn -> R`, this method returns `D2,...,Dn -> R` if `n` > 0, or `R` if `n` = 0.

    - #### arity

          public final int arity()

    - #### trueDomainIsBoxed

          public final boolean trueDomainIsBoxed(int i)

    - #### domainIsBoxed

          public final boolean domainIsBoxed(int i)

    - #### setDomainBox

          public final void setDomainBox(int i)

    - #### unsetDomainBox

          public final void unsetDomainBox(int i)

    - #### trueRangeIsBoxed

          public final boolean trueRangeIsBoxed()

    - #### rangeIsBoxed

          public final boolean rangeIsBoxed()

    - #### setRangeBox

          public final void setRangeBox()

    - #### unsetRangeBox

          public final void unsetRangeBox()

    - #### mustWrapArgument

          public final boolean mustWrapArgument(FunctionType actualType,
                                 int i)

    - #### mustUnwrapArgument

          public final boolean mustUnwrapArgument(FunctionType actualType,
                                   int i)

    - #### mustWrapResult

          public final boolean mustWrapResult(FunctionType actualType)

    - #### mustUnwrapResult

          public final boolean mustUnwrapResult(FunctionType actualType)

    - #### argumentSortsDisagree

          public final boolean argumentSortsDisagree(FunctionType actualType,
                                      int i)

    - #### resultSortsDisagree

          public final boolean resultSortsDisagree(FunctionType actualType)

    - #### flatten

          public final Type flatten()

      Flattens this function type and all function types that occur in it by uncurrying all the domains. Note that care is taken to copy the boxing masks which are set according to those of the domains and range.
      Overrides:
        `flatten` in class `Type`

    - #### curry

          public final void curry(int depth,
                   TypeChecker typeChecker)

      Transforms this function type by splitting its 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] -> A` at depth `k<n`, transforms it into `A[1],...,A[k] -> (A[k+1],...,A[n] -> A)`. Note that the boxing masks are carefully set to reflect the original type boxing information that was obtained by the `copy` method from the standardized types.
      Overrides:
        `curry` in class `Type`

    - #### curry

          public final void curry(int depth)

      Does the same as the version above, except that it is a one-time destructive procedure (similar to the two versions of the unify method).

    - #### uncurry

          public final FunctionType uncurry()

      When this function type is of the form `A[1],...,A[n] -> (B[1],...,B[m] -> R)`, this returns the function type `A[1],...,A[n],B[1],...,B[m] -> R`, making sure to preserves boxing masks appropriately.

    - #### copy

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

      Returns a copy of this FunctionType as per the renaming given by the specified HashMap. Note that copying preserves original type boxing information, including type parameters that must be treated as boxed.
      Overrides:
        `copy` in class `Type`

    - #### instantiate

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

      Returns an instantiated copy of this function type as per the specified substitution. Note that the boxing mask is set according to the nature of the domain and range types.
      Overrides:
        `instantiate` in class `Type`

    - #### unify

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

      Unifies this function type with the given type in the context of the given type-checker. Note that this may cause currying transformations to be applied as needed, unless currying has been explicitly forbidden through an `Application` whose `setNoCurrying()` method has been invoked to inhibit the currying of its operation.

      All bindings and currying transformations are appropriately trailed in the contextual type-checker for undoing purposes. If unification fails, a FailedUnificationException is thrown.

      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. Two type parameters will be considered equal only if they are identical objects (i.e., same pointers). Note that this assumes that both types are in flattened form (i.e., fully uncurryed) - which is the case of all defined symbol's types.
      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. Note that this assumes that both types are in flattened form (i.e., fully uncurryed) - which is the case of all defined symbol's types.
      Specified by:
        `isEqualTo` in class `Type`

    - #### maskString

          public final java.lang.String maskString()

    - #### toString

          public final java.lang.String toString()

      Returns a string form for a function type.
      Overrides:
        `toString` in class `java.lang.Object`