Skip to content

Record formatting feedback #5552

@kspeakman

Description

@kspeakman

The 2 recommended multi-line record formattings can be problematic. And in fact trying to use the above recommendations as a beginner was a very frustrating experience. Here's why.

The first multi-line form has editor-based issues that may require manual, line-by-line correction on indent/outdent. I stopped using this form because of the tedious formatting corrections. For example, In VS 2017 outdent will cause later fields to shift out of line with the first field, creating a compiler error until corrected.

// before outdent
    let myRecord =
        { Field1 = 1
          Field2 = " " }

// after outdent (Shift-Tab), compile error: No assignment given for field Field2
let myRecord =
    { Field1 = 1
        Field2 = " " }

The second multi-line form simply does not compile with some type definition features or provides warnings with some constructions.

type IMyInterface = interface end

// compiler error: Unexpected keyword interface
type MyRecord = {
    MyField : int
}
interface IMyInterface

// warning: "possible incorrect indentation"
let foo a =
    a
    |> Option.map (fun x -> {
            MyField = x
        })

The only record syntax I've found that always "just works" is this.

// this works with all type features, like interface
type MyRecord =
    {
        SomeField : int
    }
    interface IMyInterface

// no warning
let foo a =
    a
    |> Option.map (fun x ->
        {
            MyField = x
        })

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions