fsharp-idiom-review
Review an F# change for C#-shaped code before you finish it. Use when writing, porting from C#, or reviewing F# that returns tuples, uses out parameters or bool * value pairs, chains if/elif on discrete values, uses let mutable with loops, indexes lists by position, makes several passes over one collection, builds code text by string concatenation, matches with more than two when guards or on a tuple with more than two cases, or returns Result with a string error.
Unsigned, install at your own risk
UnverifiedThis skill has no cryptographic signature attached. We can't verify the contents match what the publisher intended.
Install this skill
No account required. Pick your tool, or use the command that detects it for you.
Run in your terminal. It detects your AI tool.
npx @skills-hub-ai/cli install fsharp-skills-fsharp-idiom-reviewManual setup by platform
Claude Code
~/.claude/skills/fsharp-skills-fsharp-idiom-review/SKILL.md
Instructions
F# idiom review
The compiler accepts C#-shaped F#. Human reviewers then ask for a different shape.
Review evidence ranks idiomatic readability and collection efficiency among the strongest categories of human comments on agent F# code.
Codex and opencode sessions also hold 5 user corrections on this subject, for example: "can use a match statement instead of a mutable".
Apply this checklist to your own diff before you finish. It is most important when you port C# code, because a line-by-line port keeps the C# shape.
For domain modeling (constrained types, private constructors, unions for states), use parse-dont-validate. This skill does not repeat it.
Checklist
Each item shows the shape to find and the shape to use. references/EXAMPLES.md has longer examples and the exceptions.
-
Record, not tuple, for named results. A function that returns or stores three or more values, or two values of the same type, returns a record.
// Before let computeTotals order : decimal * decimal * int = (subtotal, discount, itemCount) // After type Totals = { Subtotal: decimal; Discount: decimal; ItemCount: int } let computeTotals order = { Subtotal = subtotal; Discount = discount; ItemCount = itemCount } -
Option, not out parameter or
bool * value. Port a C#TryX(..., out T value)method to a function that returnsT option.// Before let tryGetRate code : bool * decimal = if code = "SAVE10" then (true, 0.10m) else (false, 0m) // After let tryGetRate code = match code with "SAVE10" -> Some 0.10m | _ -> NoneAt a call to a .NET
TryParsemethod, match the tuple once and return an option:match Int32.TryParse s with | true, v -> Some v | _ -> None. -
match, notif/elif, for discrete values. Usematchfor string literals, union cases, enum values, and tuples. Keepif/eliffor ordered numeric ranges such asif total >= 1000m.// Before if code = "SAVE10" then Some 0.10m elif code = "SAVE25" then Some 0.25m else None // After match code with | "SAVE10" -> Some 0.10m | "SAVE25" -> Some 0.25m | _ -> None -
Expression, not
let mutablewith a loop or branches. UseList.sumBy,List.fold, orList.mapfor accumulators. Bind the result of amatchorifinstead of assigning in each branch.// Before let mutable subtotal = 0m for line in lines do subtotal <- subtotal + line.Price let mutable discount = 0m if ok then discount <- subtotal * rate // After let subtotal = lines |> List.sumBy _.Price let discount = match rate with Some r -> subtotal * r | None -> 0m -
List.tryFind, not a loop with an early exit. F# has noreturn. A port offoreach ... if (...) return x;usestryFind,tryPick,exists, orforall, not a mutable flag.// Before let mutable found = None for l in lines do if found.IsNone && not l.InStock then found <- Some l // After let found = lines |> List.tryFind (fun l -> not l.InStock) -
No position index on an F# list.
xs.[i]andList.item iwalk the list from the head, so a loop over0 .. xs.Length - 1is quadratic. UseList.mapi,List.iteri, orList.indexed. Use an array when you need random access.// Before for i in 0 .. lines.Length - 1 do printfn "%d. %s" (i + 1) lines.[i].Sku // After lines |> List.iteri (fun i l -> printfn "%d. %s" (i + 1) l.Sku) -
One pass where one pass is enough. Use
List.sumByforList.map >> List.sum,List.tryFindforList.filter >> List.tryHead, andList.existsforList.filter >> List.isEmpty >> not. Do not enumerate aseqtwice: aseqfrom a query or a file runs its work again. Materialize it once withList.ofSeq, or compute the aggregates in onefold.// Before let total = lines |> List.map (fun l -> l.Price) |> List.sum // After let total = lines |> List.sumBy _.Price -
match!, notlet!and thenmatch. Intask,async, and other computation expressions, match the awaited value directly.// Before let! user = loadUser id match user with | Some u -> return u.Name | None -> return "unknown" // After match! loadUser id with | Some u -> return u.Name | None -> return "unknown" -
static member valfor a value computed once.static member X = expris a property. It runsexpron each access. Usestatic member val X = expr, or a module-levellet, for a shared value.// Before: a new options object on each access static member Options = JsonSerializerOptions(PropertyNameCaseInsensitive = true) // After static member val Options = JsonSerializerOptions(PropertyNameCaseInsensitive = true) -
A syntax API, not string concatenation, to make code or markup. When the target format has a builder (Fantomas
OakandAst, RoslynSyntaxFactory,XElement,Utf8JsonWriter), use it. Concatenated text breaks on quotes, escapes, and indentation.// Before let xml = "<item sku=\"" + sku + "\"/>" // After let xml = XElement(XName.Get "item", XAttribute(XName.Get "sku", sku)).ToString() -
An error union, not
string, inResult. A caller cannot match on astringerror, and the compiler cannot tell the caller about a new case. Give each failure a union case with typed payloads. When the errors of several functions compose, or a nested union needsResult.mapErrorat each call, use fsharp-iwsam-errors instead. A case does not hold raw input that can contain a secret, such as a URL with user info.// Before let parsePort (raw: string) : Result<int, string> = match Int32.TryParse raw with | true, p when p > 0 && p < 65536 -> Ok p | true, _ -> Error "Port is out of range" | _ -> Error "Port is not a number" // After type PortError = | NotANumber | OutOfRange of value: int let parsePort (raw: string) : Result<int, PortError> = match Int32.TryParse raw with | true, p when p > 0 && p < 65536 -> Ok p | true, p -> Error (OutOfRange p) | _ -> Error NotANumber -
Named active patterns, not more than two
whenguards or a tuple match with more than two cases. Amatchcan have more than twowhenguards, or match a tuple with more than two cases, such as theBeforeblock below. Then name each case in the words of the domain with an active pattern. With a complete active pattern ((|A|B|)), the compiler checks that the match covers each case. Change only the matches in your diff.// Before match country, weightKg with | None, _ -> 0m | Some c, w when c = "US" && w <= 1m -> 5m | Some c, w when c = "US" -> 5m + (w - 1m) * 2m | Some _, w when w <= 1m -> 15m | Some _, w -> 15m + (w - 1m) * 4m // After let (|Pickup|Domestic|International|) country = match country with None -> Pickup | Some "US" -> Domestic | Some _ -> International let (|Light|Heavy|) weightKg = if weightKg <= 1m then Light else Heavy(weightKg - 1m) match country, weightKg with | Pickup, _ -> 0m | Domestic, Light -> 5m | Domestic, Heavy extra -> 5m + extra * 2m | International, Light -> 15m | International, Heavy extra -> 15m + extra * 4m
Steps
- List each tuple return,
bool * valuepair, out parameter,if/elifchain,let mutable,fororwhileloop, list index, chained collection pass,let!followed bymatch,static memberwith a computed value, string-built code,Resultwith astringerror, andmatchwith more than twowhenguards or a tuple with more than two cases in your diff.
Done when each item is on the list. - For each item, apply the checklist entry, or keep it and state the reason. Valid reasons: a measured hot path, a .NET API that requires the shape, an ordered numeric range for
if/elif, or a match on a tuple with two cases. - Run the code and its tests again. The public behavior must not change.
Verify
Run the proof script from the skill root:
pwsh ./scripts/run.ps1
The script runs each before form and each after form and checks that they give the same result.
It shows that a caller can match each error union case, and that a string error gives only text.
It also shows that static member X = expr runs expr on each access and static member val runs it once.
It checks that the active patterns give the same result as the when guards for each input.
It fails when an expected result does not occur.
Security
Reviews (0)
Related skills
Browse all →More from F# Skills
View source →More Build skills
Browse category →Frequently asked questions about fsharp-idiom-review
What does the fsharp-idiom-review skill do?
Review an F# change for C#-shaped code before you finish it. Use when writing, porting from C#, or reviewing F# that returns tuples, uses out parameters or bool * value pairs, chains if/elif on discrete values, uses let mutable with loops, indexes lists by position, makes several passes over one collection, builds code text by string concatenation, matches with more than two when guards or on a tuple with more than two cases, or returns Result with a string error. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.
How do I install the fsharp-idiom-review skill?
Run `npx @skills-hub-ai/cli install fsharp-skills-fsharp-idiom-review` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/fsharp-skills-fsharp-idiom-review/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.
Which AI tools does fsharp-idiom-review work with?
fsharp-idiom-review runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.
Is the fsharp-idiom-review skill free?
Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.
How do I use fsharp-idiom-review after installing it?
In Claude Code, type `/fsharp-skills-fsharp-idiom-review` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.
Can I share the fsharp-idiom-review skill with my team?
Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.