Should there be some globally available equality check for all types? What about equality for function types? What if the equality check is computationally expensive?
Yes, equality should be complete. The usual equality operator found in something like C, Java, Go, etc. works with any values - primitives compared by value, while composites, functions and other stuff by reference. There is an argument for structural equality for composites, but it comes with performance penalty, so i'd ignore it for now.
Referential equality. We could design an algorithm to compare them for equality, but it will always be a nuanced topic, that is usually not even worth the effort. In practice no one really expects to compare functions this precise anyway.
It depends on the previous two points, but if we go the simplest route, then C-like equality operator is going to be very lightweight. Structural equality will be worse, but manageable. And function equality is gonna be really bad (afaik its undecidable for some definitions of equality).
In any case it's not really practical to implement equality stronger than C-like equality operator. And that pretty much removes complexity associated with other variants.
I was thinking about how we could maybe use negative variables in the "default" branch, but in the case of if-let that would be much simpler, since you only have one negated pattern to consider instead of n-many!
Yep. In my language I desugar almost all logical operators into if expressions, and that also gives rise to all sorts of interesting behaviors, similar to logical operators in js. The only thing I didn't desugar is the match operator itself, but I forgot why I decided against it (it can be simple chain of ifs). In any case, analyzing if expressions is a bit easier than whole matches. Another thing I feel is must-have in a language with patterns is an operator to just test matching (I named it is), with the rule like "if it is checked to be matching in some section of the code, then it all substitutions must be accessible there". It returns set of regular and negative substitutions (a match), which is casted to boolean in regular expressions. Following the rule, this match must be bound in if expressions with then-branch binding regular substitution set, and else-branch binding the negative set. In some sense that blurs the boundary between not-, and-and or-pattern and their boolean expression counterparts.
View all comments
Show parent comment
1
u/GidraFive May 06 '25
In any case it's not really practical to implement equality stronger than C-like equality operator. And that pretty much removes complexity associated with other variants.
Yep. In my language I desugar almost all logical operators into if expressions, and that also gives rise to all sorts of interesting behaviors, similar to logical operators in js. The only thing I didn't desugar is the
matchoperator itself, but I forgot why I decided against it (it can be simple chain of ifs). In any case, analyzing if expressions is a bit easier than wholematches.Another thing I feel is must-have in a language with patterns is an operator to just test matching (I named it
is), with the rule like "if it is checked to be matching in some section of the code, then it all substitutions must be accessible there". It returns set of regular and negative substitutions (a match), which is casted to boolean in regular expressions. Following the rule, this match must be bound in if expressions with then-branch binding regular substitution set, and else-branch binding the negative set. In some sense that blurs the boundary between not-, and-and or-pattern and their boolean expression counterparts.