[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how is polymorphism used?



On Thu, Mar 13, 2003 at 04:11:20PM -0500, Paul Steckler wrote:
> > 3. The code works with different types, but is just generic, 
> > not polymorphic.  A queue would fall under this category.  It 
> > might work on any type, but it doesn't do anything different 
> > when used with different types.
> 
> Using the same algorithm at all types is the essence of parametric
> polymorphism.

Right, but sometimes that means treating the type as a black box and
sometimes it means having polymorphic operators or higher order
functions to parameterize the operations.  In Java, the latter would
be something like a TreeMap with Comparable types (or a Comparator)
and the former would be like an array of Objects.  One relies on
polymorphism to actually act on the data it is processing, and the
other just passes the data around without ever acting on it.

> 
> > My first guess would be that in most (not all) applications 
> > there are a few generic utility classes/modules/functions and 
> > the rest of the code is pretty tied to certain types, even if 
> > the language doesn't force this.  In other words, for most 
> > code you could replace it with a statically typed language 
> > without really changing much.
> 
> Polymorphism and static typing aren't mutually exclusive; ML and 
> Haskell use polymorphism and are statically typed.

True--I should have said an explicitly typed language like C.

In terms of ML or Haskell, my question is how many different
concrete signatures tend to get generated for a polymorphically
defined function or module?

Thanks for your comments,

Russ