You have a point, but the mathematical approach of Haskell of different function cases is quite readable and straight forward. I only coded a little in Haskell and I know how to read it. I am not sure if you would consider Rust a functional language but they have pattern matching for function parameters but only you’re allowed to use one function signature unlike Haskell. Sent from my iPhone
On 10 Aug 2021, at 10:53 AM, Steven D'Aprano <steve@pearwood.info> wrote:
On Sun, Aug 08, 2021 at 11:30:20AM +0400, Abdulla Al Kathiri wrote:
For me, it looks normal because I am used to seeing pattern matching for function parameters in functional programming languages.
Can you give us a few samples from other languages? The only one I know is Haskell:
fib 0 = 0 fib 1 = 1 fib n = fib (n-1) + fib (n-2)
I don't *hate* that in Haskell, because Haskell is meant to be read almost as mathematical definitions. But Python functions are declarative, and Python code consists of statements which are executed in a defined order. I don't think that's a good match for Haskell-style syntax.
What's wrong with the straight-forward application of a match statement inside the function body? As you suggest:
def fib(*args): match args: case 0, : return 0 case 1, : return 1 case int(n), : return fib(n-1) + fib(n-2)
It costs one extra line (the match statement), but makes it explicit what we're matching. And you save having to repeat the `def fib` for every case.
Most importantly, it means that we only need one kind of pattern matching syntax, instead of two.
-- Steve _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/WCOU56... Code of Conduct: http://python.org/psf/codeofconduct/