[Haskell-cafe] MPTCs and rigid variables

Kirsten Chevalier catamorphism at gmail.com
Mon Mar 5 21:56:23 EST 2007

On 3/5/07, Simon Peyton-Jones <simonpj at microsoft.com> wrote:
> 4.  The "rigid type variable" thing isn't just an implementation question.  What *would* you like the error message to say when you write
>         f :: ([a], Int) -> Int
>         f (x:xs, y) = x+y
> Here we unify 'a' with Int, which is wrong.  What would a nicer error message say?

IMO, the "rigid type variable" error message is confusing for two
reasons: (1) it doesn't suggest to the user (or at least the
novice-to-intermediate user) what they should do to solve the problem,
and (2) it makes the user feel like they need to go read six papers on
type inference before they can make any progress when all they wanted
to do is add two numbers.

In this particular case, something like "Suggested fix: change 'a' in
the type signature to 'Int'" would be an improvement: it addresses
reason (1), and putting it ahead of the "rigid type variable" part
(e.g., textually highlighting the more newbie-friendly portion of the
error message) addresses reason (2). (I realize that the same error
might occur in cases where the type variable isn't bound by a user
type signature, but it's common enough for users to insert type
signatures when the code isn't compiling that I think it's worth it to
treat that as a special case, even if there isn't a more general way
to improve the error message.)


Kirsten Chevalier* chevalier at alum.wellesley.edu *Often in error, never in doubt
"And I have grown with each disappointment through the years" -- Great Big Sea

More information about the Haskell-Cafe mailing list