monomorphic or not?

Simon Peyton-Jones simonpj at
Thu Mar 6 06:43:08 EST 2008

| On Thu, Mar 06, 2008 at 08:56:15AM +0000, Simon Peyton-Jones wrote:
| > No, it's fine.  compress is indeed monomorphic, but since it's called
| > at exactly one type, namely Char, so it gets the monomorphic type
| > [Char] -> [Char].  That is what the Haskell Report says. (Or tries
| > to.)
| But when I modify the module header to be:
| > module Main(main,compress) where
| It still doesn't complain, it can't know that all other uses of
| 'compress' in other modules will also be at a Char type.

See 4.5.5 in the Report

Rule 1 says that 'compress' is not generalised.  So it gets the type
        [t] -> [t]
where 'a' is an as-yet-un-determined type; in implementation terms, a unification variable.

Rule 2 says "Any monomorphic type variables that remain when type inference for an entire module is complete, are considered ambiguous, and are resolved to particular types using the defaulting rules".  But in this case no monomoprhic variables remain, because by then the type of compress has been refined to [Char] -> [Char]

Well, that's the way GHC interprets the report anyway!


More information about the Glasgow-haskell-users mailing list