Skip to main content

fsharp-library-api-design

Design and change the public API of an F# library without breaking its consumers. Covers F#-specific breaking changes (new union cases, new record fields, curried and tupled forms, generic and inline functions, RequireQualifiedAccess, renamed modules), binary breaks that a clean build does not show (a new optional parameter, a wider parameter type, cross-assembly inlining of a small function body into Release consumers, --nooptimizationdata), safe extension patterns (overloads, new functions), a C#-friendly surface, SemVer for each change type, the lowest FSharp.Core version, and compatibility checks with package validation and old consumers. Use when the user adds to or changes a published F# library, asks whether a change is breaking, picks a version number, or exposes F# code to C#.

v1.0.0New

Unsigned, install at your own risk

Unverified

This 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-library-api-design
Or get the file:
Browse all CLI commands →
Manual setup by platform

Claude Code

~/.claude/skills/fsharp-skills-fsharp-library-api-design/SKILL.md

Setup guide →
0Save

Instructions

F# library API design

A published library has two contracts:

  • Source compatibility: F# and C# code that compiled against 1.0.0 compiles against 1.1.0.
  • Binary compatibility: an assembly that was compiled against 1.0.0 runs with 1.1.0.
    NuGet gives this case often. When package A was built against 1.0.0 and the app needs 1.1.0, A runs with 1.1.0 and is not compiled again.

A minor or patch version must keep both contracts. A new overload on a type member is the one exception when it makes no existing call ambiguous. It breaks a C# method group with no delegate type. A clean build of every consumer that you can see proves only source compatibility.
Many F# breaking changes do not look like breaking changes. Some are source-only, and package validation does not report them.

Changes and their results

Each row is a change to version 1.0.0 that scripts/run.ps1 proves. "Source" rebuilds an F# and a C# consumer with TreatWarningsAsErrors. FS0025, FS0044, and CS0618 are warnings that this setting makes errors. "Binary" runs a consumer that was compiled against 1.0.0 with the new DLL.

ChangeF# sourceC# sourceBinaryPackage validation
New union caseFS0025okok until a new case reaches old codenot reported
New record fieldFS0764CS7036MissingMethodExceptionCP0002
Curried function made tupledFS0001okoknot reported
[<RequireQualifiedAccess>] addedFS0039, and FS0025 in a matchokoknot reported
inline body changed, with or without --nooptimizationdataokokold body runs in F# until rebuildnot reported
Small function body changedokokold body runs in F# until rebuildnot reported
Small function body changed, --nooptimizationdata in 1.0.0 and 1.1.0okoknew body runsnot reported
Parameter made generic (int list to 'T list)okokMissingMethodExceptionCP0002
Parameter type widened (int list to seq<int>)okokMissingMethodExceptionCP0002
[<Optional; DefaultParameterValue>] parameter added to an existing memberokokMissingMethodExceptionCP0002
F# ?x parameter added to an existing memberokCS7036MissingMethodExceptionCP0002
Member added to a public interfaceFS0366CS0535TypeLoadExceptionCP0006
Module renamedFS0039CS0103TypeLoadExceptionCP0001
[<CompiledName>] added to an existing functionokCS0117MissingMethodException, except in a Release F# consumer that used cross-assembly inlining of a small bodyCP0002
[<Obsolete>] on a functionFS0044CS0618oknot reported
New overload on a type member (seq<int> beside int list, or one more parameter)okCS8917 for a method group such as var total = client.Total;okok
New overload with an unrelated reference type (Send(System.Uri) beside Send(string))FS0041 for an unannotated function parameterCS0121 for client.Send(null)okok

Read references/CHANGES.md for each change with its code and its safe alternative.

Rules

  • Extend. Do not change. Do not change the signature of a public function or member in a minor version. This includes a new optional parameter and a wider or generic parameter type. Add an overload on a type member, or add a new function next to the old one.

  • Check overload resolution. A new overload must not make an existing call ambiguous. When neither parameter type is a subtype of the other, as with Uri and string, a call that both accept is ambiguous. C# client.Send(null) then fails with CS0121. An F# call fails with FS0041 when the argument type is not known before the call, such as an unannotated function parameter. Use a new member name instead, or test these call shapes in an F# and a C# consumer, including null and a numeric literal.

  • Overloads need a type. A module function cannot have an overload. To give a module function a new parameter, add a function with a new name. Mark the old one [<Obsolete("Use X.")>] only in a major version. A consumer with TreatWarningsAsErrors fails with FS0044 or CS0618.

  • Records: a new field removes the old constructor and breaks each consumer that builds the record, including test code. When a record must grow, plan for it in the first version: expose a create function or a class with members. Use fsharp-signature-files to hide a representation.

  • Unions: a new case is a breaking change for each consumer that matches on the union. An old binary that gets the new case can run a wrong branch of its match, with no error. A rebuilt consumer that builds with warning FS0025 throws MatchFailureException on the new case. fsharp-binary-compatibility proves both results (union-new-case). Release a new case in a major version, or hide the representation before the first release. Add a case only at the end. A case in the middle changes the tag number of each later case, and an old binary runs a wrong branch of its match, with no error (union-insert).

  • Interfaces: do not add a member to a public interface. Add a new interface that inherits the old one, for example IStore2, and test for it at run time with :?.

  • Curried and tupled: keep the form of each public function. A change compiles to the same method, so package validation does not see it, but F# callers fail.

  • inline: an inline body is compiled into each caller. A fix in the body reaches a consumer only when the consumer builds again, also with --nooptimizationdata. Use inline on a public function only when it needs statically resolved type parameters.

  • Small function bodies: Release builds also copy small non-inline functions through cross-assembly inlining. The F# compiler puts optimization data in the library DLL, and an F# consumer that is built in Release copies small public function bodies from it, also through a ProjectReference. An old consumer then keeps the old body. C# consumers do not copy bodies. A library that must take body fixes with no consumer rebuild needs --nooptimizationdata from its first release:

    <OtherFlags>$(OtherFlags) --nooptimizationdata</OtherFlags>
    

    The flag does not change consumers that were compiled against an earlier DLL that had optimization data. Without cross-assembly inlining, consumer code can be slower. inline functions are still copied with the flag. Decide this before the first release.

  • Names: a renamed module, type, or function and a new [<RequireQualifiedAccess>] break callers. Add the new name and keep the old one.

C#-friendly surface

Apply these rules to new public members that C# can call:

  • Do not use F#-only types in parameters: option, voption, list, Map, Set, function types, and Async. C# must then build these values with FSharp.Core. Use seq<'T>, arrays, IReadOnlyList<'T>, delegates such as Func<'T, 'U>, and null or an overload for an absent value.
  • Do not return option, voption, function types, or Async to C#. For an absent result, return null, or use a TryX method with an outref parameter. Return a delegate instead of an F# function and Task<'T> instead of Async<'T>. A returned list, Map, or Set works in C# as a .NET collection, but IReadOnlyList<'T> or an array is easier to use.
  • An F# ?x parameter is an FSharpOption<T> parameter in C#, and C# must pass it. For a parameter that C# can leave out, use [<Optional; DefaultParameterValue(...)>] on a new member only.
  • Use [<CompiledName("PascalCase")>] on a new module function that C# calls. Do not add CompiledName to an existing function, because it renames the compiled method.
  • Return Task<'T> at the boundary. Keep Async<'T> for F# callers in a separate function or module.

Versioning

Use SemVer for each change type:

VersionAllowed changes
MajorAny break in the table above, in F# source, C# source, or binary form. This includes a new [<Obsolete>], because a consumer with TreatWarningsAsErrors fails. A new overload that makes no existing call ambiguous is the exception: it stays minor, and the release notes name it.
MinorNew types, new functions, new overloads that make no existing call ambiguous, and new members on classes.
PatchFixes that do not change the public surface. A fix to an inline body, or to a small function body without --nooptimizationdata, reaches F# callers only when they build again. Say so in the release notes.

Set the lowest FSharp.Core version that the library needs. By default, the package depends on the FSharp.Core version of the SDK (10.1.403 with SDK 10.0.403), and each consumer must then use that version or a later one. The proof pins FSharp.Core 6.0.7 in a netstandard2.0 library. An older FSharp.Core can lack functions that the code uses, so build the library with the pin:

<ItemGroup>
  <PackageReference Update="FSharp.Core" Version="6.0.7" />
</ItemGroup>

A higher minimum FSharp.Core forces consumers to upgrade. Name each increase in the release notes. A consumer that references a lower FSharp.Core gets only warning NU1605. It builds, and then fails at startup with FileNotFoundException for FSharp.Core (fsharp-binary-compatibility rule 11).

Steps

  1. Before the change, record the public surface of the built library. If fsharp-signature-files is installed, use its public-surface.ps1. Keep the output as a snapshot file. Without that script, use package validation in step 3 as the surface check.

  2. List each public change that the request needs. Find its row in the table. If a row breaks a contract, use the safe alternative from references/CHANGES.md, or make the version major.

  3. Turn on package validation against the last released version and pack:

    <PropertyGroup>
      <EnablePackageValidation>true</EnablePackageValidation>
      <PackageValidationBaselineVersion>1.0.0</PackageValidationBaselineVersion>
    </PropertyGroup>
    

    dotnet pack then fails with CP0001, CP0002, or CP0006 when a type or member signature of 1.0.0 is gone or changed. It does not report F#-only source breaks, a new union case, or a changed function body. Package validation and apicompat also miss union case order. apicompat also misses [<Literal>] values and curried and tupled changes. A --sig diff and a PublicApiGenerator snapshot show all three. Microsoft.CodeAnalysis.PublicApiAnalyzers does not run in F# projects. fsharp-binary-compatibility proves these tool results.

  4. Check both contracts with the consumers that you have:

    • Source: build each F# and C# consumer, with its tests, against the new library. For a new overload, also build the call shapes from the overload rule above.
    • Binary: build each consumer against the old version. Copy the new library DLL, and each new dependency DLL, into its output folder. Run the consumer. The output must not change.
  5. Compare the public surface with the snapshot. Each removed or changed line is a break. Each added line that C# calls must follow the C#-friendly rules above.

  6. Set the version and write a release notes entry that names each addition, each [<Obsolete>], and each FSharp.Core change.

Verify

Run the proof runner from the skill root:

pwsh ./scripts/run.ps1

The runner packs scripts/V1 as the 1.0.0 baseline. For each folder in scripts/changes, it packs the changed library with package validation. It builds the F# and C# consumers against it, and runs the 1.0.0 consumers with the new DLL. A // flags: line in a change gives compiler flags to the 1.0.0 and the changed library. It compares each result with the // expect- lines of the change and exits with code 1 on a difference. It also checks the FSharp.Core dependency of a package with and without the pinned version.

These rules are not bundled proofs: the wrong branch and the MatchFailureException for a new union case come from the union-new-case proof of fsharp-binary-compatibility, the tag change for a case in the middle comes from its union-insert proof, F# cannot declare a default implementation for an interface member, and the copy of a small body through a ProjectReference comes from a test with SDK 10.0.404. The IStore2 sample in references/CHANGES.md is not compiled by the runner. The runner gives a // flags: line to both versions, so it does not prove that a flag only in 1.1.0 leaves old consumers with the body that cross-assembly inlining copied.

This skill doesn’t include stateful context yet, instructions only. Learn about stateful skills.

Security

Loading security scan...

Reviews (0)

Browse all →
fsharp-performance-typesChoose F# collections and types for run time and allocation, and prove the result with a measurement. Use when F# code is slow or allocates too much, when a reviewer asks for fewer passes or allocations, or when you write a hot loop over list, array, seq, Map, Set, Dictionary, option, tuple, or sprintf.0 installsfsharp-nullness-interopHandle F# nullness checking (Nullable enable, FS3261, FS3262 in F# 9 and later) at .NET interop boundaries, and fix FS0041 "A unique overload could not be determined" from new BCL overloads such as TimeSpan.FromSeconds(int64). Covers BCL members that return `| null`, correct null handling with match and Option.ofObj, null leaks that the compiler does not report, and when suppression is acceptable. Use when an F# build reports FS3261, FS3262, or FS0041, when the user turns on nullness checks or TreatWarningsAsErrors, or when F# code calls .NET APIs that can return null.0 installsfsharp-signature-filesAdd F# signature files (.fsi) that expose only the API that callers use, and hide type representations so callers must use constructor functions. Covers generating a starting point with --allsigs or --sig, removing helpers from the .fsi, abstract types, attribute and interface mismatches (FS3888, FS0050, FS1200), signature errors (FS0034, FS0193, FS0238), XML docs, InternalsVisibleTo for tests, and a public-surface check of the built assembly. Use when the user asks for signature files, a smaller public API, encapsulation of an F# library, or hidden constructors.0 installsfsharp-native-aotMake F# code work under .NET Native AOT (PublishAot) and find the failures that publish warnings do not show. Covers which printf, sprintf, failwithf, and interpolated-string forms work, silent data loss from %A and ToString on unions and tuples, logging, System.Text.Json for F# records, option, list, and unions, configuration binding, warnings-as-errors, and JIT-versus-native verification. Use when an F# project sets PublishAot or PublishTrimmed, when the user asks about F# AOT or trimming, when F# output or logs differ in a native build, or when F# JSON fails with "Reflection-based serialization has been disabled".0 installsfsharp-failure-pathsMake failures in F# code explicit instead of crashing or hiding them. Use when writing or reviewing F# that calls partial functions (List.head, Seq.find, Map.find, .Value), uses failwith, falls back with defaultArg or Option.defaultValue, catches exceptions, or combines several validations into one Result.0 installsparse-dont-validatePreserve invariants in types when changing domain models, input boundaries, or state transitions.0 installs

More from F# Skills

View source →
fsharp-env-capabilitiesPass dependencies in F# as one generic env value whose capabilities are small IProvideX interfaces, so the compiler infers each function's dependency set and tests build only what a function needs. Also binds IConfiguration settings to F# types, validates them with Result at startup, and exposes the validated type as a capability instead of IOptions<T>. Use when an F# function list of dependency parameters grows, when wiring IServiceProvider or ASP.NET Core DI into F# functions, when binding or validating appsettings.json or IOptions settings in F#, when a test must substitute one dependency, or when the user says env, capability, IProvide, or environment pattern.0 installsfsharp-iwsam-errorsDesign F# error types as IWSAM leaves (interfaces with static abstract members) so each function declares only its own errors and the caller picks one edge type. Use when adding or composing Result error types across F# functions, when a nested error DU needs Result.mapError at every call, when a new error case must reach every handler, or when the user says IWSAM, error tree, or edge type.0 installsfsharp-serializationSerialize F# records, unions, options, and maps to JSON that matches a wire contract, and keep old JSON readable. Use when writing or reviewing F# code that calls System.Text.Json, configures FSharp.SystemTextJson (JsonFSharpConverter, JsonFSharpOptions), writes Thoth.Json encoders or decoders, adds a DTO layer, reads JSON from another service, or adds or renames a union case or record field that is stored or sent as JSON.0 installsfsharp-verify-apiCheck the real signature of a .NET or F# API before F# code uses it, so the build does not loop on FS0039, FS0001, FS0074, or FS0078. Use when writing F# against a NuGet package, a package version that changed its API, an unfamiliar type, or an .fsx script with0 installsoptimize-fsharp-typecheck-graphOptimize an F# project's graph-based type-checking critical path with measured compiler evidence. Use when an F# build spends substantial time in type checking, a `.graph.md` file shows excessive file dependencies, shared namespaces or auto-open modules serialize checking, signature files may unblock parallel work, or a compile-performance refactor needs source- and binary-compatibility validation.0 installsfsharp-binary-compatibilityChange a published F# library so that apps compiled against the old version still run against the new DLL with no rebuild. Covers new parameters on let-bound functions (no overloads), optional member parameters, inferred type changes, union case order and new cases, record fields, inline and [<Literal>] values, cross-assembly inlining (--nooptimizationdata), renames with CompiledName, curried and tupled parameters, abstract interface members, the FSharp.Core dependency, and automated checks with package validation, apicompat, and an F# signature diff. Use when the user changes the public API of an F# library or NuGet package in a minor or patch release, asks for a non-breaking change, or asks whether an F# change is binary compatible.0 installs

More Build skills

Browse category →
senior-frontendBuild and review React, Next.js, TypeScript or Tailwind frontends: components, scaffolding, performance and bundle size. Use whenever the user wants a new component or app, a page feels slow, the bundle is too big, or asks for a frontend code review.635 installsui-design-systemUse when building a design system: tokens, component docs, responsive scales or developer handoff. Generates tokens with design_token_generator.py.535 installsfrontend-designGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.346 installssenior-backendBuild and fix backend services: REST or GraphQL APIs, auth, microservices, PostgreSQL queries, migrations and load tests. Use whenever the user's API is slow or broken, needs login or auth added, a schema change, or a new endpoint or service scaffolded.246 installsself-improving-agentCurate what the agent has learned into durable project knowledge. Reviews Claude Code auto-memory (MEMORY.md and its topic files) for learnings worth keeping, promotes proven ones into CLAUDE.md or .claude/rules/, records a correction as a lesson that persists across sessions, prunes stale or duplicate entries, and turns a recurring fix into a reusable skill. Use whenever the user asks what you have learned or saved about the project, which memories should become permanent rules, to remember a lesson or stop repeating a mistake, or to clean up, audit or check memory health.173 installsusing-superpowersUse when starting any conversation - establishes how to find and use skills, requiring skill invocation before ANY response including clarifying questions145 installs

Frequently asked questions about fsharp-library-api-design

What does the fsharp-library-api-design skill do?

Design and change the public API of an F# library without breaking its consumers. Covers F#-specific breaking changes (new union cases, new record fields, curried and tupled forms, generic and inline functions, RequireQualifiedAccess, renamed modules), binary breaks that a clean build does not show (a new optional parameter, a wider parameter type, cross-assembly inlining of a small function body into Release consumers, --nooptimizationdata), safe extension patterns (overloads, new functions), a C#-friendly surface, SemVer for each change type, the lowest FSharp.Core version, and compatibility checks with package validation and old consumers. Use when the user adds to or changes a published F# library, asks whether a change is breaking, picks a version number, or exposes F# code to C#. 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-library-api-design skill?

Run `npx @skills-hub-ai/cli install fsharp-skills-fsharp-library-api-design` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/fsharp-skills-fsharp-library-api-design/ 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-library-api-design work with?

fsharp-library-api-design 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-library-api-design 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-library-api-design after installing it?

In Claude Code, type `/fsharp-skills-fsharp-library-api-design` (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-library-api-design 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.