silver icon indicating copy to clipboard operation
silver copied to clipboard

Operator sections

Open krame505 opened this issue 4 years ago • 4 comments

In Haskell one can write e.g. (==) or (a ==) or (== 2) to partially apply the == operator. Silver has "attribute sections" inspired by this but not operator sections (although we have pretended that they exist in some of our papers.)

Once all the built-in operators have been re-implemented as functions, operator sections should be easy to implement as a very simple extension, forwarding to partially-applied calls to the operator functions.

krame505 avatar Oct 12 '21 18:10 krame505

Syntax Suggestion: Sylvan does (_ == 3), (_ == _), etc.; I think this would be nice in Silver too, since it looks like (and maybe is implementable as) a generalization of the f(_, 3) syntax.

remexre avatar Jan 06 '25 22:01 remexre

Yeah, that does feel stylistically better, given Silver's partial application syntax differs from Haskell where one partially applies a function by omitting the argument.

krame505 avatar Jan 06 '25 22:01 krame505

Luke (accidentally?) discovered that the parentheses aren't even needed. For example one can write

map(_ == 2, i)

which IMO is just as clear as the parenthesized version. As far as I can tell, any situations where this might go wrong (e.g. x * _ + 2) would be a type error, anyway. One can still write it with parentheses when doing so is clearer.

krame505 avatar Jan 07 '25 21:01 krame505

Hmm, one other thought - the current syntax for attribute sections is (.foo) and not _.foo. And the corresponding proposed syntax for tuple selector sections in #844 is (.3). Do we want to add _.foo (can be used with parens as (_.foo)) and _.3 (usable as (_.3)) for consistency/completeness? I don't think we should drop the current attribute section syntax, that would be a lot of work, but I also don't love having two different styles.

krame505 avatar Jan 09 '25 05:01 krame505