Uniqueness of principle type? (was Re: [Haskell-cafe] Type vs TypeClass duality)

Jules Bean jules at jellybean.co.uk
Tue Oct 23 07:12:16 EDT 2007

TJ wrote:
> No. I am saying that Haskell's type system forces me to write boilerplate.

Fair enough.

> Why can't it automatically construct them then? Assuming we do have a
> syntax for "A list of objects, each of which is of some
> possibly different type 'a', subject only to the restriction that a is a
> member of typeclass Show", as the following:
> ls :: [a where Show a]
> Then I would think that all the type checker has to do would be to check that,
> a) everything you cons onto ls is an instance of class Show
> b) where you extract items from ls, you only use them as you would use
> any instance of class Show.

This is beyond the detail of my understanding of the type inference 

I believe it is to do with the requirement that expressions have a 
unique principle type. Certainly in principle the algorithm you outline 
is possible, but I don't know what else you would lose.

> And I would like to say that whether or not I need it is not the
> issue, as I currently do not in fact need it. This is a study of the
> Haskell language not my possible practical applications of it.

Whether one needs it, or does not need it, is indeed an issue: any 
change to the type inference algorithm has a cost. That cost has to be 
judged against the value of it. If an extension is seldom needed, then 
its value is low, so the cost is unlikely to be considered worth it. If 
an extension is frequently need and the cost is low, then that argues 
for it..


More information about the Haskell-Cafe mailing list