Algebraic Data Types 2019-10-03
I just completed the first draft of a direct translation of some functional red-black tree code from Haskell to Python with Structured data. It's about 5-6 times longer than the source material, some of which is attributable to the way Structured Data's interface interacts with Python conventions. A previous attempt was a bit longer, but had some functionality that the draft does not currently implement, but also it cannot implement some of the functionality that the new version will be able to.
Heavy usage of the function decorator reveals some challenges that type checkers will have to handle:
- There needs to be an idea of a "structure type" that corresponds to, and at runtime is an instance of, a tuple or an ADT class. Fortunately, none of the other matchers use instances like that.
- In the when decorator, there needs to be a connection made between pattern names and function arguments.
Hopefully the last feature I come up with for Structured Data: an attribute constructor that makes placeholders representing "the current class" and which can be used in when decorators instead of exfiltrating the function from the class scope.
Speaking of features, I should get back to that enum helper idea, probably make that its own library, unless I realize it somehow interacts with defining a Sum or Product class.
Time got way away from me. I need to stop now.
Good night.