
On Wed, Jul 20, 2011 at 02:38:39PM -0400, Tom Murphy wrote:
On 7/18/11, Brandon Allbery
wrote: [...] "Circumvents"? You make it sound like the point of typeclasses is to restrict things. In fact, the point is to *undo* the restrictions necessarily introduced by polymorphism: if you don't know the type of something, you don't know what you can do with it. Typeclasses let us say "this can be any type, but we need to be able to do <x> with it". They don't circumvent; they *add*.
I wish I could think of a good example. Since I can't, I'll just try and make my point: In a way, the point of typeclasses _is_ to restrict things: one of the things that typeclasses enables is a compile-time error if I, say, try and add Bools: by not giving Bool a Num instance, we're expressing that something can't be expressed.
I think you are both right. There's a duality here, depending on your point of view. Consider a function type blah :: Foo a => ... a ...
From the point of view of someone *calling* this function, the Foo constraint *adds* some restriction: you may only pass things whose type is an instance of Foo. If you try to pass anything else you will get an error.
From the point of view of someone *implementing* this function, the Foo constraint *removes* some restriction: if there was no Foo constraint you would not be able to do anything with any arguments of type 'a'; given the Foo constraint you can do anything you could have done without it, *plus* you can use any Foo methods.
-Brent