Hi, thank you for the comments
On Tue, 30 Jun 2020 at 07:18, Greg Ewing email@example.com wrote:
On 29/06/20 8:47 am, Daniel Moisset wrote:
You seem to be trying to shoehorn all Python data structures into looking like alebraic types, for the sole purpose of being able to claim that PEP 622 is really about algebraic types rather than pattern matching.
The goal of my notes was to read the PEP between lines, so there's some personal guess and bias, but it's not out of the blue :)
I don't think that's a helpful way of looking at things. Pattern
matching with destructuring is a more general concept. Algebraic types is just one of its applications.
I agree on this statement (except the first sentence :) )... what I'm trying to say is that the PEP has some underlying algebraic type style and making it explicit is a way to understand it with different eyes.
I think your viewpoint is coloured by languages in which algebraic types play a much more central role than they do in Python. For example, in Haskell, the usual notation for lists is syntactic sugar for an algebraic type representing a linked list.
Haskell also does some shoe-horning... integers in haskell are supposed to be an algebraic type made by the union of infinite constructors named "1", "2", "3", ... :) Even if the implementation is nothing like that, this kind of shoe-horning is useful allows you to have a coherent story and design, so I'm looking for somehting close to that in Python.
But Python lists are not linked lists, they're flexible-sized arrays, and you have to squint very hard indeed to see them as being fundamentally an algebraic type. Yet pattern matching on them makes perfectly good sense.
True. And python has already had that for ages. I'm *guessing* intent here again, but I believe that was included into the PEP because it was easy, not because it was the main concern to address.
returning by default an object __dict__ or some sort of mapping view
on the attributes could still be fine. It's not clear to me why the "keys" of this structure are placed separately.
I think the PEP explains the rationale behind the design of the matching protocol quite well. The goal is to make it as simple as possible to implement in the most common cases.
I have improved my understanding of this. I still find the protocol weak (but mostly the match, not the matched_args) even for the cases that are desired to be covered, but I'm already discussing those directly with the authors.
For me, there should be an instance method in object (that
subclasses can override) that returns the algebraic structure of the
The PEP as-is creates different destructuring views depending on which matching class you use (whicch I think relates to something that was mentioned but not discussed a lot in the python-dev list about Liskov sustitability).
I think the PEP has this right. Liskov substitutability doesn't apply to constructors -- they're not methods, and the constructor of a subclass doesn't have to accept the same arguments as that of its base class. The same thing applies to deconstructors, since they have to mirror the signature of their corresponding constructors. (...)
You're right, it was not Liskov related, but the single argument default behaviour. I was wrong about this.