I suggest you ...

Allow Unicode symbols to be used as operators

It would be great to define mathematical operators (e.g. ∀, ∑, ∩) in F#, and be able to use other Unicode symbols (such as arrows) in operators as well. So instead of saying

let inline (!++) xs = xs |> Seq.sum

you could say

let inline (~∑) xs = xs |> Seq.sum

Writing "∑myList" is much, much easier on the eyes and brain than trying to figure out what "!++myList" does.

110 votes
Vote
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Yusuf Motara shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

16 comments

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...
  • Jon Harrop commented  ·   ·  Flag as inappropriate

    Here's my hot list of operators:

    × and ⋅ same as *

    ÷ same as /

    ≤ same as <=

    ≥ same as >=

    ≠ same as <>

    ∞ same as infinity

    Less hot:

    ∧ same as &&

    ∨ same as ||

    → same as ->

    Cold:

    ∩ equivalent to Set.intersection precedence just above &&

    ∪ equivalent to Set.union precedence just above &&

    ⊂ equivalent to Set.isSubset s1 s2

    ⊄ equivalent to not(Set.isSubset s1 s2)

    ⊕ same as +

    ⊗ same as *

    ∈ same as Set.contains x s

    ∉ same as not(Set.contain x s)

    √ same as sqrt

  • Jon Harrop commented  ·   ·  Flag as inappropriate

    I would love to have unicode operators supported in F# but your example is a bad one because we can already do that with a function called capital Greek sigma:

    let inline Σ xs = Seq.sum xs

  • Eric Taucher commented  ·   ·  Flag as inappropriate

    Get's my vote.

    As an alternative means of entering the characters, one draws the character and has it entered. Here is an example of where a site takes in a drawing and converts it to a character or characters. After a while it can use Bayesian network or something to pick the one you mean. http://shapecatcher.com/

  • Rickasaurus commented  ·   ·  Flag as inappropriate

    I've got a modern APL Keyboard (you can order them from UNICOMP with USB) and I'd love to have this feature.

  • Gustavo Guerra commented  ·   ·  Flag as inappropriate

    It's not hard to type. You set up the greek keyboard on control panel and then and set a global hotkey like Ctrl+Alt+Shift to switch from/to it, then the ∑ is just the capital S, and similar for other symbols

  • Finn Neuik commented  ·   ·  Flag as inappropriate

    I've been learning a little Haskell recently and something I like about the emacs mode is that it'll do a conversion on the fly between standard keywords and unicode representations. For example typing -> results in emacs showing →. It's nice seeing things like composition, nil, etc appearing 'correctly' and you easily add more. The source code itself remains with the standard characters. It'd be great to see something similar in F# (or rather Visual Studio) as I find it sometimes makes code a little opaque when you have to chase definitions of operators. The only issue with the emacs mode is that it messes with the whitespace (e.g. forall and . ∀ , use a different number of characters) but I'm guessing that could be worked out.

  • Daniel Jackson commented  ·   ·  Flag as inappropriate

    With much improved intellisense, typing these operators might not be as big of an issue. <sarcasm>Alternatively, you could try and convince your employer to provide and gift you an "Optimus Maximus" keyboard.</sarcasm>

  • Yusuf Motara commented  ·   ·  Flag as inappropriate

    It's a bit annoying on Windows, since you have to set it up by editing a registry value and rebooting (see http://en.wikipedia.org/wiki/Alt_code).

    Then to type ∑, you turn on NumLock, hold down Alt, then press the following keys in turn: U, Numpad-Plus, 2, 2, 1, 1. (2211 is the Unicode character ∑; it can be typed either on the top-row of numbers or on the numpad). You can find more mathematical symbols here: http://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode

  • SealedSun commented  ·   ·  Flag as inappropriate

    That's a cool idea, but how do you type these characters? I'm using the macro keys on my Logitech G15 (1st gen) keyboard, but I find it far from ideal.

Feedback and Knowledge Base