Coding 2024-07-10
I'm not quite comfortable writing code yet, so let's take a look at the kinds of contracts I want to have.
The match function takes a Structure argument; this type is a union of many types. The straightforward stuff is:
- Discard should match any input, and result in an empty MatchDict object.
- Pattern should match any scalar input, and result in a MatchDict with one entry, keyed to the name of the pattern.
- A scalar structure should match an input equal to itself, producing an empty MatchDict, while any unequal input should fail the match, resulting in None.
The minor complicating factor is that I don't remember what I think matching pattern to pattern should do.
The major complicating factors are around, for one, "complex" types like tuples; there's a large amount of scaffolding around treating them in a sophisticated fashion, in the old code, and I can't jump into that. And the other is what I'm currently calling CompoundStructure. This is a marker/abstract class, and I can't see any way to express all of the expected behavior at the match function, where it's relying on polymorphism to get the behavior. Ultimately, these are kind of the same thing, it's just that I can't force builtin types to subclass from my marker.
With that in mind, it's possible to write contracts for the easy cases above, and to suppose that the hard cases should delegate to the custom class. Furthermore, those cases should probably have separate... cases...
I'm not sure whether Deal can handle the kind of type annotations I want to throw at it. I guess I'll just have to try it.
Anyway, it's late and I want to get ready for bed.
Good night.