HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Reductions

datadata Reduction

A Reduction is the result of an operation that rewrites a type ty_in. The Reduction includes the rewritten type ty_out and a Coercion co such that co :: ty_in ~ ty_out, where the role of the coercion is determined by the context. That is, the LHS type of the coercion is the original type ty_in, while its RHS type is the rewritten type ty_out.

A Reduction is always homogeneous, unless it is wrapped inside a HetReduction, which separately stores the kind coercion.

See Note [The Reduction type].

Instances1Outputable
datadata HetReduction

Stores a heterogeneous reduction.

The stored kind coercion must relate the kinds of the stored reduction. That is, in HetReduction (Reduction co xi) kco, we must have:

 co :: ty ~ xi
kco :: typeKind ty ~ typeKind xi
valuemkHetReduction
  1. :: Reduction

    heterogeneous reduction

  2. -> MCoercionN

    kind coercion

  3. -> HetReduction

Create a heterogeneous reduction.

Pre-condition: the provided kind coercion (second argument) relates the kinds of the stored reduction. That is, if the coercion stored in the Reduction is of the form

co :: ty ~ xi

Then the kind coercion supplied must be of the form:

kco :: typeKind ty ~ typeKind xi

Compose a reduction with a coercion on the left.

Pre-condition: the provided coercion's RHS type must match the LHS type of the coercion that is stored in the reduction.

valuemkCastRedn1
  1. :: Role
  2. -> Type

    original type

  3. -> CoercionN

    coercion to cast with

  4. -> Reduction

    rewritten type, with rewriting coercion

  5. -> Reduction

Apply a cast to a Reduction, casting both the original and the reduced type.

Given cast_co and Reduction ty ~co~> xi, this function returns the Reduction (ty |> cast_co) ~return_co~> (xi |> cast_co) of the given Role (which must match the role of the coercion stored in the Reduction argument).

Pre-condition: the Type passed in is the same as the LHS type of the coercion stored in the Reduction.

Homogenise a heterogeneous reduction.

Given HetReduction (Reduction co xi) kco, with

 co :: ty ~ xi
kco :: typeKind(ty) ~ typeKind(xi)

this returns the homogeneous reduction:

hco :: ty ~ ( xi |> sym kco )

Rewriting type arguments

datadata ArgsReductions

Stores Reductions as well as a kind coercion.

Used when rewriting arguments to a type function f.

Invariant: when the stored reductions are of the form co_i :: ty_i ~ xi_i, the kind coercion is of the form kco :: typeKind (f ty_1 ... ty_n) ~ typeKind (f xi_1 ... xi_n)

The type function f depends on context.