Python structural pattern matching morphs again
Python structural pattern matching morphs again
Posted Dec 3, 2020 9:44 UTC (Thu) by lxsameer (guest, #65438)In reply to: Python structural pattern matching morphs again by logang
Parent article: Python structural pattern matching morphs again
To me, it seems that because pattern matching and type systems are a trend in past few years they want them in Python otherwise it's violates Python's Zen and would be mess.
Posted Dec 3, 2020 10:41 UTC (Thu)
by rsidd (subscriber, #2582)
[Link] (1 responses)
Posted Dec 3, 2020 17:32 UTC (Thu)
by nybble41 (subscriber, #55106)
[Link]
Inferred static types are very different from dynamic types, even if they appear superficially similar at the source level. Even with polymorphism, the type of the value being matched must be known in advance for each particular instance. The compiler can use this information to generate jump tables rather than long if/else chains and to statically test for exhaustiveness in the match patterns. The simplest pattern matches (e.g. destructuring a product type) can be optimized out altogether.
You can get approximately the same behavior with runtime tests in dynamic languages, but the performance cost is considerable.
Python structural pattern matching morphs again
Python structural pattern matching morphs again