Hello,
On Sun, 27 Dec 2020 14:10:59 +0100
Dave Halter <[email protected]> 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.
--
Best regards,
Paul mailto:[email protected]
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/YNFTRO3FAJ3CIIC4NQOVOMYPR2QPALIY/
Code of Conduct: http://python.org/psf/codeofconduct/