Type Functions: Implementation Status

Parsing and Renaming

Todo (low-level):

Imported data family tycon cannot be extended (GHC claims its not in scope in the data instance declaration) - cf. MapPS.hs.

Probably remove the iso flag.

Todo (high-level):

Make the kind specification optional in family declarations. (How to do the representation in the data/newtype case is not entirely clear, as we use the presence of the kind signature at the moment to identify family declarations.)

Parse and rename equality constraints in signatures.

Defaults for associated type synonyms. (Having both a kind signature and vanilla synonym is problematic as in RnNames.getLocalDeclBinders its hard to see that not both of them are defining declarations, which leads to a multiple declarations error. Defaults are quite different from vanilla synonyms anyway, as they usually have tyvars on their rhs that do not occur on the lhs.)

Import/export lists:

We need to be able to write something like GMapKey(GMap,empty).

Export and import of data constructors declarated in data instances. We should be able to use the same syntax for the entity specs as for closed data types, but the meaning is somewhat different.

Done:

Parsing and renaming of kind signatures (toplevel and in classes).

Parsing and renaming of indexed type declarations (toplevel and in classes).

Using new syntax with family and instance on top level.

Type Checking

Todo (low-level):

data/newtype instances may not overlap. (Such definitions would always be non-confluent.)

In an AT definition, no argument variable may be repeated.

Check that the arguments of AT instances coincide with the respective instance arguments of their class.

Check that each class instance has a definition for every AT and conversely that that all defined associated types are, in fact, part of the class. (Do this in the type checker - GHC does the corresponding checks for methods in the type checker, too.)

Families declared as an AT, may not receive toplevel type instances.

For each case scrutinising an associated data type, check that all constructors have been defined in a single instance. (Maybe we can just extend the existing check that ensures that case expressions don't mix constructors of different data types.)

RHS of a type instance must be a tau type.

Check that patterns of type indexes don't contain type functions.

Construct InstInfo for type equation in tcIdxTyInstDecl1.

If an associated synonym has a default definition, use that in the instances. In contrast to methods, this cannot be overridden by a specialised definition. (Confluence requires that any specialised version is extensionally the same as the default.)

Desugaring

When a family type is exported/imported, all its instances need to be implicitly imported/exported, just as with classes.

Derivings on an associated data type declaration need to be inherited by all definitions of that data type in instances.

Todo (high-level):

Extend interface files to include equality axioms:

How do we exactly want to represent type equations in interface files?

SPJ pointed out that instances are maintained in InstEnv.InstEnv with different values for the home packages and others. Type instances may have to be maintained in a similar way, as they are also incrementally collected during compiling a program. (We probably include them in the same structure, as they will also be of type InstInfo.)