Skip to content
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

FeedBack Requested: Undeprecate Inline Record definition in Discriminated Union in F# 4.0 #1196

Closed
bikallem opened this issue May 15, 2016 · 3 comments

Comments

@bikallem
Copy link

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,

  1. 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.
  2. AFAICT this feature doesn't cause friction with existing F# features but rather enhances F# functional first approach to software development.
  3. 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.
  4. 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
  1. Since this feature is deprecated, I am assuming implementation can be revived without too much engineering/development effort.
  2. 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.

@dsyme
Copy link
Contributor

dsyme commented May 18, 2016

@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.

@dsyme
Copy link
Contributor

dsyme commented May 18, 2016

I'll close this - please add a link to the UV entry

@dsyme dsyme closed this as completed May 18, 2016
@bikallem
Copy link
Author

Indeed there is UV item asking for this specific feature. here is the link Inline Record Definition in Discriminated Unions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants