|
|
Subscribe / Log in / New account

Python structural pattern matching morphs again

Python structural pattern matching morphs again

Posted Dec 3, 2020 17:29 UTC (Thu) by NYKevin (subscriber, #129325)
In reply to: Python structural pattern matching morphs again by mathstuf
Parent article: Python structural pattern matching morphs again

Python does not meaningfully distinguish between class instantiation and function calls. If you allow destructuring the function call operator, where does it end? Would we have case x + y: print(x, y)?

IMHO this whole thing would make a lot more sense if it *just* supported the regular unpacking syntax a la PEP 448, and (maybe) a very conservative extension for matching simple enum constants. Everything else is just going to require too many weird special cases to get right.


to post comments

Python structural pattern matching morphs again

Posted Dec 3, 2020 17:55 UTC (Thu) by ms (subscriber, #41272) [Link]

> where does it end? Would we have case x + y: print(x, y)?

Haskell has n+k patterns (albeit behind an option - they're off by default), though one of the args must be a literal constant. But, err, I suspect Prolog and the halting-problem in general is where it would end if you took this to its logical conclusion.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds