fsharp / fsharp/fslang-suggestions
Allow Unicode symbols to be used as operators
- Dominant language
- No language data
- Stars
- 373
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
I propose we revisit the proposal of allowing unicode symbols to be used as operators with a simplified precedence model.
The existing way of approaching this problem in F# is to create an inline function with backticks
```fs
let ``∫`` xs = xs |> Seq.sum
//and..
let ``∪`` a b = Set.union a b
let x = a |> ``∪`` <| b
```
the proposed way of writing this is
```fs
let (∫) xs = xs |> Seq.sum
let l = ∫ [1..10]
//and..
let (∪) a b = Set.union a b
let x = a ∪ b
```
(yes my examples are silly :P , you know the real ones)
The proposal is novel in that operator precedence of unicode operators would simply be left to right. If that's undesirable perhaps a attribute for the precedence with level 1 being lowest and defaulting to whatever ~ is when unspecified. We could then document each of the levels in https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/symbol-and-operator-reference/ so that the creators of operators could set up precedence in intuitive ways.
```fs
[]
let (∫) xs = xs |> Seq.sum
[]
let (∪) a b = Set.union a b
```
## Pros and Cons
## The advantages of making this adjustment to F#
- It would help allow mathematically inclined users to more naturally express things in code.
- Mathematical symbols are easier to type in windows now that `win + ;` exists.
- People who have difficulty reading mathematical operators would also have difficulty reading the math
- People who want mathematical notation are already writing code like this using ` ``∫`` `.
- Removing backticks makes it easier to read
## The disadvantages of making this adjustment to F# are ...
- Operator precedence would basically be left to right for unicode operators
- More operators.
- Math
- A more APL style programming experience (left to right) or a new attribute
- `let x = 🧨7`
## Extra information
### Full disclosure, This has been kind of proposed before, please review. I'm hoping to revisit it now that data science and scientific computing is a target audience and that I'm proposing a simplified approach to operator precedence.
#224
> As discussed in the comments in the original submission, this is a minefield.... Deciding the precedence for such operators is really hard. It would also create swathes of unreadable F# code. I'll close this since we've previously decided not to do this in F# 2.0, and there has not yet been a major change of circumstance to warrant altering this which addresses the concerns. - Don Syme
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: (put links to related suggestions here)
#224
## Affidavit (please submit!)
Please tick this by placing a cross in the box:
* [X] This is not a question (e.g. like one you might ask on [stackoverflow](http://stackoverflow.com)) and I have searched stackoverflow for discussions of this issue
* [X] I have [searched both open and closed suggestions on this site](http://github.com/fsharp/fslang-suggestions/issues) and believe this is not a duplicate
* [X] This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.
Please tick all that apply:
* [X] This is not a breaking change to the F# language design
* [X] I or my company would be willing to help implement and/or test this
## For Readers
If you would like to see this issue implemented, please click the :+1: emoji on this issue. These counts are used to generally order the suggestions by engagement.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the proposal and the related issue #224, focusing on Unicode operator syntax and the suggested precedence models. No implementation files, tests, or compiler entry points are named, so the work first requires settling the language-design questions and defining acceptance criteria before implementation can begin.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fsharp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100