Hi Matthias,

There has been some back-and-forth during the years on how to improve sum types in Python in this community, but lately personally I've come to the realization the existing infrastructure (unions, enums, literals) is very good already.

Are unions enough for your use case?

```
@dataclass
class Rectangle:
    width: float
    length: float

@dataclass
class Circle:
    radius: float

@dataclass
class Prism:
    width: float
    height: float

Shape = Rectangle | Circle | Prism
```

You can exhaustively match on this if you know the `assert_never` trick, and I find it works very well.

On Mon, Mar 20, 2023 at 3:29 PM Matthias Gramberg via Typing-sig <typing-sig@python.org> wrote:
I come from the FSharp community.

Thanks for considering this, ADTs are particularly missing for me in today's Python.
I am used to structure all my code with them, and so is the whole community at F#.

One thing I like to mention regarding the naming:

@choice
class

I how I would define it. Not only does it say, what it does (opposite to how its implemented) it also aligns nicely with

@data
class

@sealed doesn't say much about its usage.

I am also interested about the syntax for "the next stage of the object", like in:

type Shape =
    | Rectangle of width : float * length : float
    | Circle of radius : float
    | Prism of width : float * float * height : float

How would you do that?
_______________________________________________
Typing-sig mailing list -- typing-sig@python.org
To unsubscribe send an email to typing-sig-leave@python.org
https://mail.python.org/mailman3/lists/typing-sig.python.org/
Member address: tinchester@gmail.com