-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "Make .Is* discriminated union properties visible from F#" #402
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are more suggestions than anything else
Also might be worth mentioning that existing DUs that define |
It is mentioned in Compatibility / Is this a breaking change? |
Co-Authored-By: Phillip Carter <pcarter@fastmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there. This will need a snippet describing compatibility with the existing Is*
members you have access to on the Option<'T>
and ValueOption<'T>
types.
|
||
* If this is a change or extension to FSharp.Core, what happens when previous versions of the F# compiler encounter this construct? | ||
|
||
It is not directly an extension to FSharp.Core, but it does apply to union types declared in FSharp.Core: `option`, `Result`, `Choice`. Previous versions of the F# compiler do not allow invoking the generated members on these types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't true for Option<'T>
or ValueOption<'T>
. See here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Option<'T>
is easy: IsSome
and IsNone
are already visible, so there is no change.
For ValueOption<'T>
, there are also visible IsSome
and IsNone
, in addition to the hidden IsValueSome
and IsValueNone
. So there are two possible routes:
- make them visible (which makes them redundant with the existing
IsSome
/IsNone
) - keep them hidden (which makes
ValueOption<'T>
unique among all union types for not havingIs{{UnionCaseName}}
properties)
I think I'm in favor of the former, for consistency. Plus it's probably simpler to implement than making an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume we can't remove the existing IsSome/None
, but adding IsValueSome/None
would effectively make them aliases of the former, in which they would then probably be unique in our ecosystem.
It's a tough call. For parity you would like to have them, but different members that do the exact same thing brings confusion, and unless the tooltip would clearly describe that they are synonyms, I'm afraid programmers will have to research what the differences are and you'll end up answering questions similar to whether String
or string
has better performance / should be preferred / has different semantics etc.
Of course, the answers will be simple, they're equal, but I think it's better to prevent the questions rising in the first place.
But then there's the argument of parity, auto generated code, predictability, orthogonality etc. It's a tough call ;).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the exact stance on obsoleting API is, but it could be acceptable to mark the existing ValueOption IsSome/IsNone properties [<Obsolete>]
to reduce confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tarmil I think your preference here is spot on: hiding IsValueSome
/IsValueNone
for ValueOption. Can you make a note of that in the RFC?
I like the RFC, it's quite clear I think, but I do have a few general remarks / requests:
|
The "natural" way of implementing this is to generate the Is/Tag properties earlier (into the TAST) rather than in IlxGen.fs. I don't think this technique causes any compat problems but this should be considered when reviewing the implementation. |
No description provided.