[Python-ideas] generic code and dependent types

Steven D'Aprano steve at pearwood.info
Fri Aug 15 14:26:09 CEST 2014


On Fri, Aug 15, 2014 at 06:56:46AM -0400, Neal Becker wrote:
> I'm interested in the proposals for adding type annotation.  Coming from some 
> experience with generic code in c++, one of the difficult issues has been 
> reasoning about dependent types in generic code.
> 
> In general, we need to be able to declare a type via an arbitrary metafunction
> 
> some_metafunction<T>::type F (...
> 
> It is also useful to be able to write something like:
> 
> typedef typeof (int() * float()) my_type;
> 
> I wonder if any of the proposals will be able to handle this sort of algebra on 
> types?  I think it's needed to truly support generic code.


Let's pretend that this is a Python mailing list, and that some readers 
aren't familiar with C++ generic syntax :-) What does 

typedef typeof (int() * float()) my_type;

do? From a Python perspecive, that looks like type(0*0.0) which will 
return float. Presumably that's not what you want, or you would have 
just said "float". So what am I missing?

(Apart from years of C++ experience.)


-- 
Steven


More information about the Python-ideas mailing list