I suggest we ...

Inline Record Definition in Discriminated Unions

type shape =
(**)| Circle of
(*....*) { centerX : float
(*......*) centerY : float
(*......*) radius : float
(*....*) }
| Rect of
(*....*) { x_lo : float
(*......*) y_lo : float
(*......*) x_hi : float
(*......*) y_hi : float
(*....*) }

Recently Added to OCaml

30 votes
Sign in
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Jared Hester shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →


Sign in
Sign in with: facebook google
Signed in as (Sign out)
  • Alexei Odeychuk commented  ·   ·  Flag as inappropriate

    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.

  • Alexei Odeychuk commented  ·   ·  Flag as inappropriate

    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.

  • Huw Simpson commented  ·   ·  Flag as inappropriate

    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.

F# Language

Feedback and Knowledge Base