Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 2, 2025

Summary

Addresses the user question in issue about how to format multiline lazy expressions in F#. The issue asked whether lazy expressions with multiline content should follow the function application rule or the constructor/member invocation rule.

Changes

1. Added "Formatting lazy expressions" section to F# formatting guide

Added a new section in docs/fsharp/style-guide/formatting.md that provides clear guidance on formatting both single-line and multiline lazy expressions:

Single-line lazy expressions:

let x = lazy (computeValue())

Multiline lazy expressions:

let v =
    lazy (
        // some code
        let x = computeExpensiveValue()
        let y = computeAnotherValue()
        x + y
    )

The guidance clarifies that lazy expressions follow the function application pattern: the opening parenthesis remains on the same line as the lazy keyword, with the expression body indented one level and the closing parenthesis aligned with the opening.

2. Enhanced lazy expressions reference documentation

Updated docs/fsharp/language-reference/lazy-expressions.md to include:

  • A new "Formatting" section with a practical multiline example
  • Cross-reference link to the detailed formatting guidance in the style guide

Resolution

This provides the answer to the user's question: multiline lazy expressions should follow the function application rule, with the pattern lazy ( keeping the opening parenthesis on the same line as lazy, which is consistent with other function applications that have multiline arguments in the F# style guide.

Fixes #<issue_number>

Original prompt

This section details on the original issue you should resolve

<issue_title>Lazy multiline parenthesis expression</issue_title>
<issue_description>Hello, I'm wondering what the recommended way is to write a multiline lazy expression.

let v =
    lazy (
        // some code
        // other code
        myFunctionCall x y z
    )

Should it follow the function application rule and be something like

lazy
    (multlilineExpression)

or does it follow the Formatting constructors, static members, and member invocations rule?

lazy (
    multilineExpression
)

Document Details

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

Comments on the Issue (you are @copilot in this section)

Fixes #24977

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.


Internal previews

📄 File 🔗 Preview link
docs/fsharp/language-reference/lazy-expressions.md docs/fsharp/language-reference/lazy-expressions
docs/fsharp/style-guide/formatting.md docs/fsharp/style-guide/formatting

@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Oct 2, 2025
@Copilot Copilot AI changed the title [WIP] Lazy multiline parenthesis expression Add formatting guidance for multiline lazy expressions in F# Oct 2, 2025
@Copilot Copilot AI requested a review from BillWagner October 2, 2025 13:11
Copilot finished work on behalf of BillWagner October 2, 2025 13:11
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready for final review.

@BillWagner BillWagner marked this pull request as ready for review October 2, 2025 17:50
@BillWagner BillWagner requested review from a team as code owners October 2, 2025 17:50
@BillWagner BillWagner requested a review from IEvangelist October 2, 2025 17:51
@T-Gro T-Gro merged commit 702157f into main Oct 3, 2025
20 checks passed
@T-Gro T-Gro deleted the copilot/fix-5bee3b0e-b467-462f-af83-bcdbba5140fb branch October 3, 2025 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-fsharp/svc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lazy multiline parenthesis expression
3 participants