4 ms·
I like the implementation of the "Enum" class, especially the way they allow for enums with variant behavior and "abstract Enums" (something I could have used i
by LeafStorm 13y ago
I like the implementation of the "Enum" class, especially the way they allow for enums with variant behavior and "abstract Enums" (something I could have used in Java recently).
But, ever since I found out about algebraic data types from other languages, I keep wanting those. There's not quite a good way to do those in Python. (I've used both "tuple subclass" and "__slots__," but both of those have their own little quirks.)
- shoo 13y agoif python were to have algebraic data types, it might also need pattern matching.
- Daishiman 13y agoYes, for better of worse Python is nowadays fairly conservative in introducing backward-incompatible syntax changes, and pattern matching would probably require quite a bit of new syntax (and benefits a lot from a strong compiler).
- gonnakillme 13y agoI don't think pattern matching is necessary for ADTs. It's useful, but you could have e.g. > if MyType.ConstructorA(a): > ... > elif MyType.ConstructorB(a): > ... or even something like > with MyType.ConstructorA(a) as b, c: > ... > else with MyType.ConstructB(a) as d: > ... a "with/else with" construct would be a fairly straightforward addition to Python's "context manager" interface.