[Python-Dev] Adding NewType() to PEP 484

rndblnch rndblnch at gmail.com
Tue May 31 15:55:53 EDT 2016


Guido van Rossum <gvanrossum <at> gmail.com> writes:

> 
> Also -- the most important thing.  What to call these things? We're
> pretty much settled on the semantics and how to create them (A =
> NewType('A', int)) but what should we call types like A when we're
> talking about them? "New types" sounds awkward.

back in high school, i was introduced to c programming with the "disciplined
C" preprocessor [0].
it made the distinction between information type and representation type
(e.g. between the semantic and the implementation).
those new types where created using typedefs and were named 'parallel types'
below is the relevant part of the dcc presentation:

"""
a major innovation of Disciplined C is the notion of "parallel type", that
allows a distinction between information type and representation type. The
following:

typedef int Tindex, Tval;
typedef Tindex Trow, Tcol;

creates four distinct types, but which all accept the same operations and
the same constants as the "representation" type ('int' here). Tindex, Tval,
Trow and Tcol are examples of "information" types, because they convey an
idea of the semantics of the corresponding objects. For example, they may be
put to use in a checkers playing program: Tval will name 'int's that
represent values of checkers, Trow and Tcol, 'int's that represent row and
column indexes, Tindex, generic type for indexes.
Tindex, Tval, Trow and Tcol are called parallel types; in fact, a type T1 is
said to be parallel to a type T2 iff both are defined through a chain of
typedefs starting from the same 'baseType', with no intervening qualifier
nor modifier (pointer/array/function decla- rator, see grammar in Appendix
A). In other words, T and T2 must be strict synonyms of baseType.
"""

renaud

0. Disciplined C

ACM SIGPLAN Notices Homepage archive
Volume 30 Issue 12, Dec. 1995
Pages 43 - 50
http://dl.acm.org/citation.cfm?id=219726.219747
http://www.digiater.nl/openvms/freeware/v50/dcc/dcc-v2_7d/dccarticle.ps



More information about the Python-Dev mailing list