Haskell and principal types

Olaf Chitil olaf@cs.york.ac.uk
Wed, 10 Oct 2001 18:13:49 +0100


Hi Karl-Filip,

> (Mark Jones's THIH algorithm, as
> well as other algorithms built on W, fails to type some programs
> containing type synonyms).

Are you thinking of the following kind of problem?

type T a = Bool

b :: Eq a => T a
b = True

x = b

Gives in Hugs:
Type checking      
ERROR "Test.hs" (line 8): Unresolved top-level overloading
*** Binding             : x
*** Outstanding context : Eq b

The problem is the lazy expansion of type synonyms in the type inference
algorithm. To produce better type error messages a type synoym is only
expanded when it is unified with some different type.

There isn't any problem if you first eagerly expand all type synonyms
and thus eliminate them from your program and then perform type
inference, is there?

Ciao,
Olaf

-- 
OLAF CHITIL, 
 Dept. of Computer Science, University of York, York YO10 5DD, UK. 
 URL: http://www.cs.york.ac.uk/~olaf/
 Tel: +44 1904 434756; Fax: +44 1904 432767