Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Ternary equality / between comparator #676
Ternary equality / between comparator
I propose we add support for the "between" ternary syntax:
The existing way of approaching this problem in F# is to write a multi-expression comparison:
Pros and Cons
The advantages of making this adjustment to F# are a more succinct and legible syntax for testing a value between two other values.
The disadvantages of making this adjustment to F# are:
Estimated cost (XS, S, M, L, XL, XXL): L/XL
Related suggestions: #675
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
I'm not sure this applies. Taking your suggestion literally (that is, without suggesting updated syntax), the following will lead to a different result:
true > false && false > false // original syntax for "between", yields false true > false > false // new syntax for "between" currently yields true, but should then become false
The other thing about "breaking change" being the one you already mentioned: ternary operators are now not allowed, so it will require careful thinking finding out whether chained operators could now suddenly be redefined as ternary (think
Note also that ternary operators are rare, most languages (though notably not F#) support only the
I don't disagree at all.
As a regular, non-expert, user of F#, I think this whole idea is "meh", I don't think it's something that needs to make it in the spec. (I mostly proposed it so that we can have the discussion on it now, and get it out of the way.) Being on the low-end of the expertise spectrum, it really wouldn't convince me all that much to use it.
While it adds a little value (arguable), some of the situations you mentioned to create problems. In Slack, Diego Esmerio (@Nhowka) mentioned the following active pattern that does the same thing:
Personally, I think this would be a far better feature to include in the core F# spec, and would alleviate both issues much more cleanly and idiomatically. With this pattern, I wouldn't need to have
Yes, it is trivial to add the
As an alternative, have a look here, it has two operators defined that act as 'between": http://www.fssnip.net/9y/title/Between-operators
@abelbraaksma I was actually thinking about that this morning, because I added it to my own extensions library. I went with two items:
But, alas, it still doesn't answer the
I'd prefer to see this type of a pattern-match capability built-in once we nail those questions down, because I think it's immensely more useful in this scenario.
@cartermp To be fair, the only argument I would make the opposite is that F# is a language of conveniences, no matter how small. Something like this adds another convenience to the language. (Not that such a reason justifies it.)
I'm on the fence about this anymore, I think it would make the syntax for such things clearer, but it's not something I use (or would) a lot anyway.