Home

GHType Inference

Alexey

Currently, Generic Haskell requires explicit specification of generic functions. This page documents the ongoing effort to add type inference to the Generic Haskell compiler.

Prototype

This is an implementation prototype for the algorithm described in Type Inference for Generic Haskell.

The prototype has been tested with GHC 6.4 .

Obtaining and building

To obtain the prototype you need to invoke darcs as follows:

darcs get http://www.cs.uu.nl/~alexey/repos/GH-type-infer/

To compile the prototype you need to install the parser combinators distributed with the Haskell Utrecht Tools library.

To build the prototype, simply type make:

make

Running the prototype

You can take a look at the examples in the test directory.

Examples for generic equality:

$ ./mygh -d 5 -i tests/Eq.ghs
(line 3, column 9)*4* (line 3, column 9) Generic scheme for eq is {|G_a|} G_a->G_a->Bool)
(line 16, column 4)Type :  => (List Int)->Bool

Example for reduce function:

$ ./mygh -d 5 -i tests/reduce2.ghs
(line 1, column 9)*4* (line 1, column 9) Generic scheme for reduce is
                                         {|G_a|} forAll a69.a69->G_a->a69)
(line 12, column 4)Type :  => M_a70->Bool->M_a70

In the two examples above, we ran the frontend with a debug level option of 5 (-d 5). That is the level for printing the types of all the program bindings.

Additionally, you will notice a construct in the programs used for type inspection.

Note: The prototype currently lacks the simplifier function. As a consequence some corner cases are not typeable. A new version is in preparation.

Technical report

The technical report may be downloaded from Type Inference for Generic Haskell.

-- AlexeyRodriguez - 14 Oct 2005