On Sun, 27 Dec 2020 14:10:59 +0100 Dave Halter email@example.com wrote:
I'm late, but I still wanted to add that I share some of the criticism that Mark has brought up.
I'm in love with Rust's pattern matching, so I feel like I'm not against pattern matching generally. However I feel like while the PEP is well written, there are some things that it does not tackle:
- Sum Types aka Tagged Unions are what makes pattern matching
necessary. I think we should rather have a discussion about inclusion of Sum Types.
Python had sum types (well, superset of them) since ~forever (just like any other object-oriented language). Your typical Haskell sum datatype:
data Tree a = Leaf a | Branch (Tree a) (Tree a)
directly translates to:
class Tree: pass class Leaf(Tree): def __init__(self, val): ... class Branch(Tree): def __init__(self, l, r): ...
"Leaf" and "Branch" are the tags you're looking for.
Recent dataclasses cut on the amount of boilerplate required.