Closed
Description
A common paradigm in functional programming is a function whose implementation is determined by matching the input. This is supported in coconut by either addpattern
functions or traditional match statements.
addpattern
can be unnecessarily verbose, especially if you like descriptive function names. This also makes refactoring more annoying as now you have to rename the function multiple times.
match def neg_one_if_zero(x if x == 0)=-1
addpattern def neg_one_if_zero(x)=x
Traditional match statements do not work for assignment functions (#832):
def f(x)=
match x:
case 0: -1
case _: x
^ │Coconut exiting with error: CoconutParseError
Even if this worked, it would be overly verbose compared to the rest of Coconut which has very streamlined, terse syntax.
I propose a syntax similar to Haskell or StandardML
def f(x)
| 0 =
# some code
-1
| _ = x