4 ms·
I remember reading a Perl 6 design document back in the day that made a convincing argument that operator precedence should be a partial instead of a total orde
by codeflo 5y ago
I remember reading a Perl 6 design document back in the day that made a convincing argument that operator precedence should be a partial instead of a total order. The language was supposed to have user defined operators. The idea was that you would make some declarations that your new operator would bind e.g. "between * and +", or "tighter than *". The system would build up a minimal partial order that satisfied these constraints.
One of nice things about such a system is its compositionality: If you mix and match custom operators from different modules, you wouldn't get a conflict or a random precedence order, instead, you'd simply be forced to disambiguate using parentheses.
Contrast this with Haskell, which also has custom operators, but only a fixed number of precedence slots (10 IIRC), and some libraries really suffer from the fact that there's no "good one" available that works for the intended usage.
- zokier 5y agoDocumentation of Raku (neé Perl 6) custom operator precedence mechanism https://docs.raku.org/language/functions#Precedence https://docs.raku.org/language/functions#Precedence
- agumonkey 5y agoI'm stumped by the fact that haskell relies on a fixed slot count.
- patrec 5y agoYup, Fortress had the same idea, I wonder if independently.