Python and generic programming

Christophe Cavalaria chris.cavalaria at
Wed Oct 27 00:07:26 CEST 2004

Alex Martelli wrote:

> Christophe Cavalaria <chris.cavalaria at> 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
You must admit that C++'s templating works very well for that. Well, at
least this is what I call generic programing : the ability to code
something in a type independent way and expect it to work with whatever
type I throw at it if it makes sense.

More information about the Python-list mailing list