seeking ideas for short lecture on type classes

Dean Herington heringto@cs.unc.edu
Sun, 26 Jan 2003 19:07:01 -0500 (EST)


On Sun, 26 Jan 2003, Norman Ramsey wrote:

>  > > In a fit of madness, I have agreed to deliver a 50-minute lecture
>  > > on type classes to an audience of undergraduate students.  These
>  > > students will have seen some simple typing rules for F2 and will
>  > > have some exposure to Hindley-Milner type inference in the context
>  > > of ML.
>  > 
>  > Will they have had exposure to more "traditional" OO programming?  If
>  > so, it might be useful to note the difference between Haskell type
>  > classes and C++/Java/whatever classes, namely that Haskell decouples
>  > types and the interfaces that they support.  The advantage is that you
>  > can extend a type with a new interface at any point, not just when you
>  > define the type.
> 
> Hmm --- you are talking about the `instance' declarations, right?
> 
> A fact that I know but don't understand the implication of is that
> Haskell dispatches on the static type of a value, whereas OO languages
> dispatch on the dynamic type of a value.  But I suspect I'll leave
> that out :-)

Perhaps I misunderstand, but I would suggest that "fact" is, if not 
incorrect, at least oversimplified.  I would say Haskell dispatches on the
dynamic type of a value, in the sense that a single polymorphic function
varies its behavior based on the specific type(s) of its argument(s).
What may distinguish Haskell from typical OO languages (I'm not an expert
on them) is that in Haskell such polymorphic functions could (always or at
least nearly so) be specialized statically for their uses at different types.

Dean