[Python-ideas] "Sum" Type hinting [was: Type hinting for path-related functions]

Greg Ewing greg.ewing at canterbury.ac.nz
Mon May 16 19:34:38 EDT 2016

Guido van Rossum wrote:
> On Mon, May 16, 2016 at 7:45 AM, Koos Zevenhoven <k7hoven at gmail.com 
> <mailto:k7hoven at gmail.com>> wrote:
>     On Mon, May 16, 2016 at 4:57 AM, Guido van Rossum <guido at python.org
>     <mailto:guido at python.org>> wrote:
>     [...]
>>  unions in Python are always tagged (since you can always
>     introspect the object type).

The "Sum" types talked about in the referenced article are
what Haskell calls "algebraic types". They're not really the
same as the Union[X,Y] types we're talking about here,
because a Union type simply tells the type checker that
one of a number of different types could be present at
run time. The code might introspect on the type, but it
doesn't have to do anything special to access one of the
branches of the union -- it just goes ahead and uses the

An algebraic type, on the other hand, is a new type of
run-time object that has to be explicitly unpacked to
access its contents. It's more like a class in that


More information about the Python-ideas mailing list