hazel icon indicating copy to clipboard operation
hazel copied to clipboard

User defined operators

Open claban3 opened this issue 3 years ago • 9 comments

This adds expression level user-defined operators into Hazel. Some important tidbits of information for testing these changes:

  • Precedence and associativity of operators are determined by the first operator in the user op (though the next thing-to-do is determining precedence by looking at each operator in the user op).
  • Operators are defined in let patterns by constructing on top of wildcards, and currently must be surrounded in underscores in order for them to be used as binary operators in expressions. (Future work could be to customize fixity like in Agda).
  • User operators are constructed in expressions by constructing operators on top of hazel-defined operators (e.g. <+>+ --> ++).
  • Type checking of user ops is the same as for 2-ary functions.

This PR also attempts to standardize the precedence of type level operators. Please verify the "type precedence test" in SkelParserTests.re.

claban3 avatar Jan 22 '21 00:01 claban3

Gotta resolve conflicts first by merging in dev into your branch

dm0n3y avatar Feb 05 '21 23:02 dm0n3y

  • It is not possible to shadow the built-in operators, e.g. _+_. This may be a good thing, but if so we should probably have a warning / error on bindings of those.

Makes sense, I will add a "got reserved operator" error to the cursor context menu. However,

  • It is not possible to use the "." in custom operators. Again this may be for the best given the other ways we are using ".", but it makes it so you can't define float versions of things using the same idiom as built in operators.

I'm not sure what would make sense as valid feedback in this situation? Maybe treat it as invalid text? I don't think the float idiom makes sense here, because you could create an operator of type int -> float -> int for example.

claban3 avatar Mar 11 '21 22:03 claban3

I'm not sure what would make sense as valid feedback in this situation? Maybe treat it as invalid text? I don't think the float idiom makes sense here, because you could create an operator of type int -> float -> int for example.

imo we can just let the users make sure it makes sense to put the dot in their operator from the perspective of notational convention (with maybe a future style checker / linter warning in questionable situations)

cyrus- avatar Mar 11 '21 22:03 cyrus-

imo we can just let the users make sure it makes sense to put the dot in their operator from the perspective of notational convention (with maybe a future style checker / linter warning in questionable situations)

So add . to the user defined operator regex?

claban3 avatar Mar 11 '21 22:03 claban3

Actually let's hold off on that for now, that might cause trouble with float parsing and with labeled tuple stuff that Erin is working on. we can return to that question in the future.

cyrus- avatar Mar 11 '21 22:03 cyrus-

Sounds good!

claban3 avatar Mar 11 '21 23:03 claban3

@claban3 could you comment with a screenshot example of defining an operator and using it?

dm0n3y avatar Mar 14 '21 17:03 dm0n3y

Analytically: image

Synthetically: image

claban3 avatar Mar 14 '21 17:03 claban3

Let me know if you want more examples

claban3 avatar Mar 14 '21 17:03 claban3

Archiving this because it cannot be merged into Hazel 3, but we are planning to follow the same specification more-or-less -- cross-referenced in #828. Thank you for all the hard work on this @claban3 !

cyrus- avatar Sep 30 '22 04:09 cyrus-