Open cloudRoutine opened 7 years ago
This feature already exists in the form: type Shame = | Circle of centerX: float * centerY:float * radius:float | ... It supports pattern matching by the order of the field as well as the name.
I believe that discriminated unions containing inline records in their declarations is a great idea. It would improve the F# expressiveness. It is good that the F# language supports tuples with named items as Huw Simpson mentioned, but inline records in declarations of discriminated union types would be a new way of expressing programmers' ideas in code. F# should remain competitive and be better than OCaml, I think.
I think inline records can be named as "record expressions" or "records of an anonymous type" for the sake of terminology consistency in F#. There are object expressions in F# that are useful when there is no need to define a class. I think a situation when a language user needs to use a record expression of a compiler-generated anonymous record type instead of a user-defined record type is quite possible in practice and it will be good if the language has a solution able to meet competition with other programming languages.
This feature is currently deprecated in F# 3.0 and above. It was available I believe until F# 2.0. Maybe we can change the title to 'Undeprecate inline record in DU'. I have also created a ticket/issue in github visual f# repo. https://github.com/Microsoft/visualfsharp/issues/1196#issuecomment-220172524
For me, the big advantage is that it would allow mutable inline records. This can be huge for performance.
Inline Record Definition in Discriminated Unions [12555765]
Submitted by Jared Hester on 3/2/2016 12:00:00 AM
[ 30 votes ]
type shape = ()| Circle of (....) { centerX : float (......) centerY : float (......) radius : float (....) } | Rect of (...._) { xlo : float (......_) ylo : float (......_) xhi : float (......_) yhi : float (....) } Recently Added to OCaml https://blogs.janestreet.com/ocaml-4-03-everything-else/