Hi, Dag Sverre Seljebotn wrote: > Robert wrote: >> cdef max(generic a, generic b): >> return a if a >= b else b >> >> where "generic" is a special type.
This is called "parametric polymorphism", a concept from ML and one of the reasons why compiled ML code is so freaking fast. http://en.wikipedia.org/wiki/Polymorphism_(computer_science)#Parametric_polymorphism > Yes, I really, really like this one. So do I. Very explicit. How would that map to C space? Would you have functions called ..._generic_int_float_max(int a, float b) ? What about extension types? Imagine a stupid type called "int_float" ... > If "generic" is not clear enough, "auto" is another option. I prefer "generic". "auto" sounds more like "find the correct type yourself" and doesn't make it clear that this can lead to code duplication and actually works for multiple type candidates. > def inline add(a, b): return a + b > > would handle overflowing conditions differently depending on whether the > inline keyword is present or not. This would not exactly be obvious to the > user. Agreed. > This could be an argument for waiting with supporting explicit overloading > until the time that Python decides to do so. Overloading and parametric polymorphism are orthogonal concepts. Both have their niche. Intuitively, I would expect both to be similarly complex to implement, but PP looks much more pythonic to me and can be done without caring about Python compatibility, so I would propose to go for that one first. Stefan _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
