Skip to content

Consolidate F# optional parameters documentation #47580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 25, 2025

The F# documentation for optional parameters was incomplete and fragmented across multiple files. The methods.md file only covered C# interop-style optional arguments using [<Optional; DefaultParameterValue>] attributes, while missing the native F# optional parameter syntax using ?.

This PR consolidates all optional parameter documentation into the parameters-and-arguments.md file with clear distinctions between the two forms:

  1. Optional Arguments with Late Defaults (F# Native): Using ? syntax for F#-idiomatic optional parameters that are interpreted as F# option types
  2. Optional Arguments with Early Defaults (C# Interop): Using [<Optional; DefaultParameterValue>] attributes for C# compatibility, introduced in F# 4.1

The methods.md file now simply references the comprehensive documentation in parameters-and-arguments.md, eliminating duplication and providing developers with a single authoritative source for all optional parameter information.

This addresses the concern raised in the issue that the F# language's native optional parameter mechanism was not covered in the documentation, which was "very curious" given how commonly this technique is used.

Fixes #45813.


💡 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/members/methods.md Methods
docs/fsharp/language-reference/parameters-and-arguments.md Parameters and Arguments

@Copilot Copilot AI changed the title [WIP] No information provided on optional parameters Consolidate F# optional parameters documentation Jul 25, 2025
@Copilot Copilot AI requested a review from gewarren July 25, 2025 18:37
Copilot finished work on behalf of gewarren July 25, 2025 18:37
@gewarren gewarren marked this pull request as ready for review August 4, 2025 23:18
@gewarren gewarren requested review from BillWagner and a team as code owners August 4, 2025 23:18
@gewarren gewarren enabled auto-merge (squash) August 4, 2025 23:18
Comment on lines +127 to +128
- [Optional arguments with late defaults (F# native)](#optional-arguments-with-late-defaults-f-native)
- [Optional arguments with early defaults (C# interop)](#optional-arguments-with-early-defaults-c-interop)
Copy link
Member

Choose a reason for hiding this comment

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

Is this terminology used or explained anywhere else in the docs?

I understand from the implementation perspective what it means, but maybe puting the names late / early exposes too much detail here? (without further explanation).

- [Optional arguments with late defaults (F# native)](#optional-arguments-with-late-defaults-f-native)
- [Optional arguments with early defaults (C# interop)](#optional-arguments-with-early-defaults-c-interop)

### Optional arguments with late defaults (F# native)

You can specify an optional parameter for a method by using a question mark in front of the parameter name. From the callee's perspective, optional parameters are interpreted as the F# option type, so you can query them in the regular way that option types are queried, by using a `match` expression with `Some` and `None`. Optional parameters are permitted only on members, not on functions created by using `let` bindings.
Copy link
Member

Choose a reason for hiding this comment

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

Should also mention usage of defaultArg and shadowing to convert an optional argument to a value.
Possibly also mention the advantage - unlike "C# style extensions", this allows authors of the method to tell if caller passed in a value or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No information provided on optional parameters
3 participants