Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 14, 2025

Summary

This PR addresses issue #45234 by clarifying how expression-to-string conversion works in F# interpolated strings.

Problem

The documentation for F# interpolated strings explained typed interpolated strings (with format specifiers like %s{expr}) but did not specify what conversion mechanism is used for non-typed interpolated strings (simple {expr} syntax). Users were left uncertain about how their expressions would be converted to strings.

Solution

Added a clarification in the Remarks section that explicitly documents:

  • Non-typed interpolated strings use the ToString() method to convert expressions to strings
  • When an expression evaluates to null, an empty string is used instead
  • Typed interpolated strings with format specifiers follow the rules defined for that specific format specifier

This aligns with the F# compiler implementation as confirmed by @T-Gro's reference to the source code.

Example

// Non-typed: uses ToString()
let age = 30
printfn $"Age: {age}"  // Calls age.ToString()

// Typed: follows format specifier rules
printfn $"Age: %d{age}"  // Uses the %d format specifier conversion

Also added ai-usage: ai-assisted frontmatter per .NET documentation guidelines.

Original prompt

This section details on the original issue you should resolve

<issue_title>For Interpolated Strings, we should indicate what kind of conversion is used.</issue_title>
<issue_description>
While for "Typed Interpolated Strings" the conversion of the expression to a string is precisely defined, there is no such indication for non-typed conversion. I assume the string operator is used. Briefly mentioning this in the Remarks section would be helpful.


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)

@BillWagner ping @dsyme for your thoughts here. @BillWagner @T-Gro

When I read the spec, it looks like the conversion does use the string operation, unless the destination is an IFormattable. If so, I'll get a fix in place.</comment_new>
<comment_new>@T-Gro
For interpolated strings, I believe it uses ToString() (unless null).
https://github.com/dotnet/fsharp/blob/bd346da564d516d60bec00c509315ac1903e64e4/src/FSharp.Core/printf.fs#L907-L933

Fixes #27048


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Internal previews

📄 File 🔗 Preview link
docs/fsharp/language-reference/interpolated-strings.md Interpolated strings

@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Oct 14, 2025
@Copilot Copilot AI changed the title [WIP] Add indication of conversion for non-typed interpolated strings Document ToString() conversion for F# interpolated strings Oct 14, 2025
@Copilot Copilot AI requested a review from BillWagner October 14, 2025 16:07
Copilot finished work on behalf of BillWagner October 14, 2025 16:07
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 14, 2025 21:01
@BillWagner BillWagner requested review from a team as code owners October 14, 2025 21:01
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses issue #45234 by clarifying the string conversion mechanism used in F# interpolated strings. The documentation previously explained typed interpolated strings but left users uncertain about how expressions are converted to strings in non-typed interpolated strings.

  • Added explicit documentation for ToString() conversion in non-typed interpolated strings
  • Clarified null handling behavior (converts to empty string)
  • Distinguished between non-typed and typed interpolated string conversion rules
  • Added required AI usage frontmatter per .NET documentation guidelines

@BillWagner BillWagner merged commit f98a1d6 into main Oct 16, 2025
10 checks passed
@BillWagner BillWagner deleted the copilot/update-remarks-for-interpolated-strings branch October 16, 2025 14:26
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.

For Interpolated Strings, we should indicate what kind of conversion is used.

3 participants