Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 10, 2025

Fixes #[issue-number]

Summary

This PR adds documentation for chaining multiple cons patterns together in F# pattern matching, addressing a gap in the existing documentation.

Changes

Added a new example demonstrating how to use multiple cons patterns consecutively to match lists that start with specific sequences of elements. This is a useful pattern that was previously undocumented.

Before: The documentation only showed the basic cons pattern (head :: tail) for decomposing a list into its first element and remaining elements.

After: The documentation now includes an example showing how to chain cons patterns:

match xs with
| 'A'::'B'::t -> "starts with 'AB'"
| 'A'::t -> "starts with 'A'"
| 'C'::'D'::t -> "starts with 'CD'"

This pattern is particularly useful when you need to match lists based on their first few elements, providing a more elegant alternative to using list patterns with fixed lengths.

Files Changed

  • docs/fsharp/language-reference/pattern-matching.md - Added explanatory text and reference to new code snippet
  • samples/snippets/fsharp/lang-ref-2/snippet4819.fs - New runnable example demonstrating multiple cons patterns

The example code has been tested and verified to compile and run correctly with F# Interactive.

Original prompt

This section details on the original issue you should resolve

<issue_title>Include multiple cons sample</issue_title>
<issue_description>
[Enter feedback here]
For the cons pattern matching section, a very useful construct that should be included in the documentation is the multiple cons pattern:

match xs with
| 'A'::'B'::t -> "starts with 'AB'"
| 'A'::t -> "starts with 'A'"
| 'C'::'D'::t -> "starts with 'CD'"

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 #28742


💬 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/pattern-matching.md docs/fsharp/language-reference/pattern-matching

@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Oct 10, 2025
@Copilot Copilot AI changed the title [WIP] Include multiple cons sample in documentation Add multiple cons pattern example to F# pattern matching documentation Oct 10, 2025
@Copilot Copilot AI requested a review from BillWagner October 10, 2025 15:34
Copilot finished work on behalf of BillWagner October 10, 2025 15:34
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 13, 2025 15:26
@BillWagner BillWagner requested review from a team as code owners October 13, 2025 15:26
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 enhances the F# pattern matching documentation by adding an example for chaining multiple cons patterns together, addressing a gap in the existing documentation where only basic cons patterns were demonstrated.

  • Adds documentation and example showing how to chain cons patterns like 'A'::'B'::t
  • Creates a new runnable code snippet demonstrating practical usage
  • Provides better coverage of cons pattern capabilities in F# pattern matching

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
docs/fsharp/language-reference/pattern-matching.md Adds explanatory text and reference to new code snippet for multiple cons patterns
samples/snippets/fsharp/lang-ref-2/snippet4819.fs Creates new runnable example demonstrating chained cons pattern matching
Comments suppressed due to low confidence (1)

docs/fsharp/language-reference/pattern-matching.md:1

  • Missing AI usage disclosure. Add the ai-usage: ai-assisted frontmatter key/value pair to indicate this content was created with AI assistance.
---

@T-Gro T-Gro merged commit ce7a5ee into main Oct 14, 2025
14 checks passed
@T-Gro T-Gro deleted the copilot/add-multiple-cons-sample branch October 14, 2025 13:05
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.

Include multiple cons sample

3 participants