Typing system vs. Java
Christian Tanzer
tanzer at swing.co.at
Wed Aug 1 11:44:58 EDT 2001
"Alex Martelli" <aleaxit at yahoo.com> wrote :
> "Christian Tanzer" <tanzer at swing.co.at> wrote in message
> news:mailman.996592198.30711.python-list at python.org...
> """
> > poor programming on my part, but I can't even think how one would type a
> > function like say:
> >
> > def f(zs): return reduce( lambda x, y: x + y, zs )
>
> Genericity (templates in C++) this is not a problem -- you get one
> instance of `f` for each type `zs` you happen to apply `f` to.
>
> Disclaimer: C++ templates don't allow different return types for such
> functions, but that's a restriction of C++, not of genericity. IIRC,
> """
>
> Beg pardon?
>
> template<class A, class B>
> A myfunction(const B& b)
> {
> return b;
> }
>
> Maybe you mean that C++ doesn't *automatically INFER* A when
> you just call myfunction(something)? But, you CAN partially
> specify myfunction<int>(something) [or, of course, totally
> specify myfunction<int,double>(something)], if you have a
> standard-compliant C++ compiler.
You're right, I was mixing things up. The restriction I remembered is
related to overload resolution not to templates.
Shows that I'm slowly recovering from my past immersion in C++ <wink>.
The traces of obscure bits of knowledge fade. I should refrain from
making passing comments about C++ arcana in the future, I guess.
> Back to Python -- programming in Python has always felt to
> me a *LOT* like generic programming
Yup. Only, in Python it's very implicit.
The nice thing about Ada and Eiffel generics is that the requirements
on the generic parameters are spellt out explicitly. For most
application areas, Python still wins hands down, though.
--
Christian Tanzer tanzer at swing.co.at
Glasauergasse 32 Tel: +43 1 876 62 36
A-1130 Vienna, Austria Fax: +43 1 877 66 92
More information about the Python-list
mailing list