by LeafStorm · 13y ago · 0 comments
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.)
> 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.