Comment by sanxiyn
3 years ago
Python is not the first language to have customizable pattern matching. Scala can do the same with extractor objects.
3 years ago
Python is not the first language to have customizable pattern matching. Scala can do the same with extractor objects.
Yep. Honestly this seems fine - pattern matching is ultimately just a function call, you can immediately see where it is (and hopefully even click through to the code from where the pattern is defined), there's no "magic" action-at-a-distance.
Customizable pattern matching is in fact unusual, although not unheard of. Traditional pattern matching is very much not a function call, because it is compiled with assumption that it can't be customized and no arbitrary user defined code is executed. In particular, usual compilation scheme guarantees that subterms are not matched more than once, but that can't be guaranteed with customizable patterns.