I suggest we ...

Add "row polymorphism" aka "extensible records"

In F# there is no way to write a function that can work on similar records.

If I have two records

type Organisation = { Name: string, Country: string }
type User = { Name: string, Profession: Profession }

and would like to write a function that operates on the common (name: string) fields I need to rewrite my records.

What I would like is a way to write a function that can work with all records that have a field (Name: string)

Here is an example with pseudocode.
Note: I do not propose this exact syntax.

// Named takes a record with at least a name field
// but can have many more in addition to that, denoted by the 'a
type 'a Named = { Name: string | 'a }

let printName (a : 'a Named) : string =
sprintf "Name: %s" a.Name

It's already possible to simulate this, but you'd have to replace your records, see here: http://stackoverflow.com/questions/29531852/does-f-have-row-polymorphism-or-something-similar

This feature is implemented in PureScript and Elm.

Elm uses the Name "Extensible Records", see: http://elm-lang.org/docs/records#record-types
Purescript: https://leanpub.com/purescript/read#leanpub-auto-record-patterns-and-row-polymorphism

16 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Joris Morger shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    2 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...

      F# Language

      Feedback and Knowledge Base