[Haskell-cafe] MPTCs and rigid variables

Claus Reinke claus.reinke at talk21.com
Tue Mar 6 17:47:06 EST 2007

> Error message:
> Inferred type is not as polymorphic as type signature claims.
>  Inferred type: [Char]
>  Expected type: [a]
>    Provided by the type signature:
>      foo :: [a]
>    at ~/foo.hs:1
> (`a', a polymorphic type variable, could not be unified with `Char', a
> monotype.)
> In the expression: "hello" at ~/foo.hs:1:8
> In the definition of `foo': foo = "hello"
> How's that sound?

too complicated? more explanation isn't always more helpful. the user is confused
at this point, and more information might mean more confusion. compare with

    Hugs> let {foo :: [a];foo = "hello" } in "oops"
    ERROR - Inferred type is not general enough
    *** Expression : foo
    *** Expected type : [a]
    *** Inferred type : [Char]

    Prelude> let {foo :: [a];foo = "hello" } in "oops"
        Couldn't match the rigid variable `a' against `Char'
          `a' is bound by the type signature for `foo'
          Expected type: [a]
          Inferred type: [Char]
        In the definition of `foo': foo = "hello"
        In the definition of `it':
            it = let
                   foo :: [a]
                   foo = "hello"
                 in "oops"

personally, i like the Hugs version best, but the GHC version is consistent
and informative as well. the problem is that GHC refers to a new concept,
rigid variables, whereas Hugs keeps things basic (and even that takes some
getting used to for beginners). rigidness is a useful concept, once you get used
to it. and GHC's message actually contains an explanation of what rigid means 
in this context, but that in itself isn't obvious when the user is freshly confused 
by that new term (not to mention the rejected program).

perhaps just replacing the line

    `a' is bound by the type signature for `foo'


    instantiating `a' with `Char' would conflict with the explicit type signature for `foo'

might help. perhaps a section in the user's guide on the topic "how to interpret
error messages" (Simon Thompson had such a thing for the mysteries of Hugs 
messages), and a "dictionary of terms used" (briefly explaining 'rigid' and the like) 
would not go amiss, either. these days, they could perhaps be a wiki, growing as
needed, but you'd want to copy snapshots into releases, right into the user's guide.


ps. i was somewhat shocked to read that SPJ wants FDs gone.

More information about the Haskell-Cafe mailing list