Parameterized Types
Martin von Loewis
loewis at informatik.hu-berlin.de
Mon Jan 15 18:29:36 EST 2001
Roy Katz <katz at Glue.umd.edu> writes:
> I came across http://www.python.org/~guido/static-typing/ the other day.
> Some things that struck me as odd:
>
> - parameterized types:
>
> class foo<TYPE>: pass
> def func<TYPE>: pass
>
> Why is this necessary? I think the point of parameterized types is
> to tell the Python compiler that we are only going to use TYPE and
> TYPE. Is this correct?
Yes.
However, you may want to use foo or func with a number of different
types. Each usage effectively gives you a different definition of foo
or func; for each specific usage, you can still tell what type TYPE
refers to.
> Which begs the question: is it possible to write an analyzing
> tracer which traces the types of objects and generates efficient code?
> for example -- the gcd() function:
>
> def gcd(a,b):
> if a>b: return a
> return b
>
> Now, if in my program all I pass to gcd() are int's, the tracer would
> recognize this.
One strategy is to automatically specialize gcd for ints, and use this
specialization every time gcd is called with ints; it would use a
different specialization if somebody passes different arguments.
> The slides expressed inlining and explicit forms of declarations;
> is it possible to come to a concensus before TMTOWTDI?
Static typing is not appearing tomorrow; there's plenty of time to
settle a syntax (although probably not by means of consensus ...).
Regards,
Martin
More information about the Python-list
mailing list