Type Checking with Indexed Type Synonyms

Outline

method can be proven correct by establishing a connection
between type function and CHR derivations

Background

GHC has now FC as its typed intermediate language.
In a next step, we wish to add type functions to
GHC's source language. Type functions in combination
with type annotations and GADTs allow us to type check
some interesting programs.

if we include the local assumptions C, the combined system Ax /\ C is non-confluent (interpreted as a rewrite system)

Possible solutions:

Enforce syntactic conditions such that Ax /\ C is confluent.
It's pretty straightforward to enforce that Ax and
constraints appearing in type annotations and data types
are confluent. The tricky point is that if we combine
these constraints they may become non-confluent.
For example, imagine

The point is that only during type checking we may
encounter that Ax /\ C is non-confluent!
So, we clearly need a better type checking method.

A second attempt

To solve (C implies t1=t2) with respect to Ax

First:

We interpret Ax /\ C as a rewrite system (from left to right) and

perform completion until the rewrite system is confluent.

We exhaustively apply rewrite rules on t1 and t2, written t1 -->* t1' and t2 -->* t2' and check that t1' and t2' are syntactically equivalent.

Step 1b) is new and crucial. For confluent rewrite systems the
checking step 2) will work fine (we also need termination of course).
But how do we now that completion will succeed?
The important condition is to guarantee that Ax is confluent (and
terminating) then completion will be successful (i.e. terminated
and produce a confluent rewrite system).

We can verify that the completion method success by showing that each critical pair arises in the `corresponding' CHR derivation (this derivation terminates if the axiom system is confluent and terminating, hence, we'll only encounter a finite number of critical pairs, hence, completion terminates).

axiom vs local assumption case

NOTE: We may need both orientation see above example.
We assume that symbol t refers to types NOT containing type functions and s refers to types which may contain type functions (can be lifted, more below)

Explaining completion in terms of CHRs.
Above translates to

T t1 ... tn b <==> C
T t1' ... tn' b' /\ C'

where s is translated to (C | b) and s' is translated to (C | b')

(see above where each type function type is represented by
a variable under some CHR constraints)

The type functions

s' = phi(s)
phi(s) = s'

resulting from completion 'appear' in the CHR derivation
(i.e. the operational effect is the same)