Safe Haskell | Safe-Inferred |
---|---|

Language | Haskell2010 |

## Synopsis

- data Reduction = Reduction {}
- type ReductionN = Reduction
- type ReductionR = Reduction
- data HetReduction = HetReduction Reduction MCoercionN
- data Reductions = Reductions [Coercion] [Type]
- mkReduction :: Coercion -> Type -> Reduction
- mkReductions :: [Coercion] -> [Type] -> Reductions
- mkHetReduction :: Reduction -> MCoercionN -> HetReduction
- coercionRedn :: Coercion -> Reduction
- reductionOriginalType :: Reduction -> Type
- downgradeRedn :: Role -> Role -> Reduction -> Reduction
- mkSubRedn :: Reduction -> Reduction
- mkTransRedn :: Coercion -> Reduction -> Reduction
- mkCoherenceRightRedn :: Role -> Reduction -> CoercionN -> Reduction
- mkCoherenceRightMRedn :: Role -> Reduction -> MCoercionN -> Reduction
- mkCastRedn1 :: Role -> Type -> CoercionN -> Reduction -> Reduction
- mkCastRedn2 :: Role -> Type -> CoercionN -> Reduction -> CoercionN -> Reduction
- mkReflRedn :: Role -> Type -> Reduction
- mkGReflRightRedn :: Role -> Type -> CoercionN -> Reduction
- mkGReflRightMRedn :: Role -> Type -> MCoercionN -> Reduction
- mkGReflLeftRedn :: Role -> Type -> CoercionN -> Reduction
- mkGReflLeftMRedn :: Role -> Type -> MCoercionN -> Reduction
- mkAppRedn :: Reduction -> Reduction -> Reduction
- mkAppRedns :: Reduction -> Reductions -> Reduction
- mkFunRedn :: Role -> FunTyFlag -> ReductionN -> Reduction -> Reduction -> Reduction
- mkForAllRedn :: ForAllTyFlag -> TyVar -> ReductionN -> Reduction -> Reduction
- mkHomoForAllRedn :: [TyVarBinder] -> Reduction -> Reduction
- mkTyConAppRedn :: Role -> TyCon -> Reductions -> Reduction
- mkClassPredRedn :: Class -> Reductions -> Reduction
- mkProofIrrelRedn :: Role -> CoercionN -> Coercion -> Coercion -> Reduction
- mkReflCoRedn :: Role -> Coercion -> Reduction
- homogeniseHetRedn :: Role -> HetReduction -> Reduction
- unzipRedns :: [Reduction] -> Reductions
- data ArgsReductions = ArgsReductions !Reductions !MCoercionN
- simplifyArgsWorker :: HasDebugCallStack => [PiTyBinder] -> Kind -> TyCoVarSet -> Infinite Role -> [Reduction] -> ArgsReductions

# Reductions

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].

#### Instances

type ReductionR = Reduction Source #

A `Reduction`

in which the `Coercion`

has `Representational`

role.

data HetReduction Source #

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

data Reductions Source #

A collection of `Reduction`

s where the coercions and the types are stored separately.

Use `unzipRedns`

to obtain `Reductions`

from a list of `Reduction`

s.

This datatype is used in `mkAppRedns`

, `mkClassPredRedns`

and `mkTyConAppRedn`

,
which expect separate types and coercions.

Invariant: the two stored lists are of the same length, and the RHS type of each coercion is the corresponding type.

Reductions [Coercion] [Type] |

mkReduction :: Coercion -> Type -> Reduction Source #

Create a `Reduction`

from a pair of a `Coercion`

and a 'Type.

Pre-condition: the RHS type of the coercion matches the provided type (perhaps up to zonking).

Use `coercionRedn`

when you only have the coercion.

mkReductions :: [Coercion] -> [Type] -> Reductions Source #

Create `Reductions`

from individual lists of coercions and types.

The lists should be of the same length, and the RHS type of each coercion should match the specified type in the other list.

:: Reduction | heterogeneous reduction |

-> MCoercionN | kind coercion |

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

coercionRedn :: Coercion -> Reduction Source #

Turn a `Coercion`

into a `Reduction`

by inspecting the RHS type of the coercion.

Prefer using `mkReduction`

when you already know
the RHS type of the coercion, to avoid computing it anew.

reductionOriginalType :: Reduction -> Type Source #

Get the original, unreduced type corresponding to a `Reduction`

.

This is obtained by computing the LHS kind of the stored coercion, which may be slow.

Downgrade the role of the coercion stored in the `Reduction`

.

mkSubRedn :: Reduction -> Reduction Source #

Downgrade the role of the coercion stored in the `Reduction`

,
from `Nominal`

to `Representational`

.

mkTransRedn :: Coercion -> Reduction -> Reduction Source #

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.

mkCoherenceRightMRedn :: Role -> Reduction -> MCoercionN -> Reduction Source #

:: Role | |

-> Type | original type |

-> CoercionN | coercion to cast with |

-> Reduction | rewritten type, with rewriting coercion |

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

.

mkGReflRightMRedn :: Role -> Type -> MCoercionN -> Reduction Source #

mkGReflLeftMRedn :: Role -> Type -> MCoercionN -> Reduction Source #

mkAppRedns :: Reduction -> Reductions -> Reduction Source #

:: ForAllTyFlag | |

-> TyVar | |

-> ReductionN | kind reduction |

-> Reduction | body reduction |

-> Reduction |

Create a `Reduction`

associated to a Π type,
from a kind `Reduction`

and a body `Reduction`

.

Combines `mkForAllCo`

and `mkForAllTy`

.

mkHomoForAllRedn :: [TyVarBinder] -> Reduction -> Reduction Source #

Create a `Reduction`

of a quantified type from a
`Reduction`

of the body.

Combines `mkHomoForAllCos`

and `mkForAllTys`

.

mkTyConAppRedn :: Role -> TyCon -> Reductions -> Reduction Source #

`TyConAppCo`

for `Reduction`

s: combines `mkTyConAppCo`

and `mkTyConApp`

.

mkClassPredRedn :: Class -> Reductions -> Reduction Source #

:: Role | role of the created coercion, "r" |

-> CoercionN | co :: phi1 ~N phi2 |

-> Coercion | g1 :: phi1 |

-> Coercion | g2 :: phi2 |

-> Reduction | res_co :: g1 ~r g2 |

Create a `Reduction`

from a coercion between coercions.

Combines `mkProofIrrelCo`

and `mkCoercionTy`

.

homogeniseHetRedn :: Role -> HetReduction -> Reduction Source #

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 )

unzipRedns :: [Reduction] -> Reductions Source #

Obtain `Reductions`

from a list of `Reduction`

s by unzipping.

# Rewriting type arguments

data ArgsReductions Source #

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.

simplifyArgsWorker :: HasDebugCallStack => [PiTyBinder] -> Kind -> TyCoVarSet -> Infinite Role -> [Reduction] -> ArgsReductions Source #