Python and generic programming

Alex Martelli aleaxit at yahoo.com
Tue Oct 26 23:58:42 CEST 2004


Christophe Cavalaria <chris.cavalaria at free.fr> wrote:

> Oliver Fromme wrote:
> 
> > The appropriate type checking is done at compile time.  That
> > is, if your program calls sort with two lists of different
> > type (e.g. a list of strings and a list of ints), then the
> > compiler will detect that and report an error.
> 
> This must be a bad example because I expect to be able to sort a list of
> integers and a list of strings with the same sort function.

Haskell should have no problem with that, thanks to typeclasses; but I
don't think ML-family languages have that (though O'Caml has always, for
years, been gaining oodles of features so fast I can't tell what is in
it or not any more;-).

But I agree with you -- generic programming should mean the compiler
instantiates as many concrete versions of the 'template' function as
needed... ideally with full type inferencing (which in C++'s templating
"sort of works BUT", but in good typesystems such as Haskell's or ML's
should just work...).


Alex



More information about the Python-list mailing list