Python and generic programming

Steven Bethard steven.bethard at gmail.com
Mon Oct 25 11:41:24 EDT 2004


Oliver Fromme <olli <at> haluter.fromme.com> writes:

> For example, a function can take an argument that is
> either an integer or a string (or a list or whatever)
> and it does _not_ have to be known at compile time
> which of those is the case.  But the compiler _does_
> ensure that the function will work correctly for every
> case (by checking that the pattern matching covers
> every case, and within each case, the respective type
> of the argument _is_ known and is checked at compile
> time).
> 
> I call that dynamic.

I'm not clear from your description (maybe you could show an example or two?)
but I gather you could either be talking about union typing, where at compile
time a variable is declared as, e.g. (list OR int), or parametric polymorphism,
where a variable's type is parameterized by another type, e.g. list<type>.  In
either of these cases, I would typically still call it static typing because the
possible types are still resolved at compile time.  (The first will be handled
much like a C union, and the second will typically be stored as a list of
objects, with some run-time checking of type inserted, as in Java 1.5.)

Steve




More information about the Python-list mailing list