You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
This is not a breaking change to the F# language design
I would be willing to help implement and/or test this
I or my company would be willing to help crowdfund F# Software Foundation members to work on this
The text was updated successfully, but these errors were encountered:
It is a nicely written suggestions and I like the idea of extending abilities in pattern matching.
That being said, I'm trying to see if F# couldn't be made super clever in such case by doing that unified binding automatically, so it wouldn't even require the cast in this case (but the proposed syntax could be supported as well for defining the type explicitly).
It would work by identifying the most specialized common subtype that can unify the bindings.
I think having the unification work without extra syntax would be very nice and keep that feature approachable to the newcomers.
I get the proposal, which I haven't commented on before. But it is just too specific and rare to be needed in the core language. The active pattern workaround looks OK to me
Allow upcasting in pattern match expressions
I propose we enable some syntax to upcast a bound identifier in a pattern matching expression.
Consider this simple example:
As expected, this code yields a message like:
I propose we add an upcast syntax so you can write something like:
In the pattern match body, the identifier
b
would then be typedBase
.Alternatives
Make no changes to the language and instead structure your code like this:
This works, but when there are many cases, or when
b.SomeBaseMember
is actually a complex expression, this becomes less than ideal.A better workaround is to declare an active pattern:
However, this is still not as elegant as an upcast operator built into the pattern matching language.
Instead of adding new syntax, use the current type check pattern:
This currently produces a compiler error:
Pros and Cons
Pro: A more elegant syntax to solve the problem above.
Con: Requires implementation in the compiler
Extra informtion
Estimated cost (XS, S, M, L, XL, XXL): S (?)
Affadavit (must be submitted)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: