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
Attempting to define a single case DU with inline records gives a deprecation error.
type T = T of {a:int; b:string};;
type T = T of {a:int; b:string};;
--------------^^^^^^^^^^^^^^^^^
.... \Local\Temp\stdin(3,15): error FS0035: This construct is deprecated: Consider using a separate record type instead
Could this feature perhaps be un-deprecated? As it is such a useful feature to have when you want to do type-driven-development. Useful because,
The code is concise as you don't have to define a separate type just so that you can use it in a Discriminated type. This feature would nicely complement a use-case where the record type definition is only used in the context of a DU case. In such cases declaring a global record type seems to be redundant and verbose. As F# favors conciseness of code expressiveness, I believe this feature will be welcomed by existing and new F# developers alike.
AFAICT this feature doesn't cause friction with existing F# features but rather enhances F# functional first approach to software development.
It seems Named/Labeled tuple in DU doesn't seem to allow declaring mutable members, for example, this is not possible as of now, type t = T of a:mutable int * b: string. I am assuming since a normal record type allows this, it will also be available in DU record type definition.
Named/Labeled tuple goes some way to enhance readability of code. However, since the name/label doesn't stick(or is not binded strongly as in record member), the same member is labelled differently in different parts of the code. This negates the readability benefit of labelled tuple in a large code-base where each developer can label the same member differently. When reviewing such code one has to frequently refer to the original definition to interpret the meaning behind the label. For example, given a DU type T = T of name:string * age:int. A developer can pattern match this without respecting the original label,
let name = function T(field1,_) -> field1
I believe inline record can enforce the naming of the tuple labels more effectively. Additionally one doesn't have to invent new variable names in pattern matches, eg. if F# allows inline records, we can pattern match as such instead,
let name = function T a -> a.name
Since this feature is deprecated, I am assuming implementation can be revived without too much engineering/development effort.
This feature is available in other ML languages such as SML and Ocaml(4.03) - of which F# also traces its roots and is a continuation of ML tradition - where it is part of the functional programming idiom. This feature will also make it easier to port - in particular- OCAML code to F#.
In summary, inline records in DU is such a useful feature that I believe it should be revived in F#. At this point I am curious to know what led to the deprecation of this feature in the first place. Feedback welcome.
P.S. If this is better served as a language RFC then I can move this issue to F# lang design RFC repo. I am starting here so that I can get some feedback, interest and viability of this feature from MS F# designers/implementers.
The text was updated successfully, but these errors were encountered:
@neolem Yes, this should go to http://fslang.uservoice.com, thanks. There may already have been a UV entry, I'm not sure. If it's approved-in-principle then we move to an RFC.
Attempting to define a single case DU with inline records gives a deprecation error.
Could this feature perhaps be un-deprecated? As it is such a useful feature to have when you want to do type-driven-development. Useful because,
type t = T of a:mutable int * b: string
. I am assuming since a normal record type allows this, it will also be available in DU record type definition.type T = T of name:string * age:int.
A developer can pattern match this without respecting the original label,I believe inline record can enforce the naming of the tuple labels more effectively. Additionally one doesn't have to invent new variable names in pattern matches, eg. if F# allows inline records, we can pattern match as such instead,
In summary, inline records in DU is such a useful feature that I believe it should be revived in F#. At this point I am curious to know what led to the deprecation of this feature in the first place. Feedback welcome.
P.S. If this is better served as a language RFC then I can move this issue to F# lang design RFC repo. I am starting here so that I can get some feedback, interest and viability of this feature from MS F# designers/implementers.
The text was updated successfully, but these errors were encountered: