fsharp-binary-compatibility
Change 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.
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-binary-compatibilityManual setup by platform
Claude Code
~/.claude/skills/fsharp-skills-fsharp-binary-compatibility/SKILL.md
Instructions
F# binary compatibility
A change is binary compatible when an app that was compiled against v1 still runs,
with the same results, after you replace the library DLL with v2. The app is not
rebuilt. A successful build of the solution proves only source compatibility,
because the build compiles every consumer again.
F# adds traps that C# does not have. A let function cannot have overloads. The
compiler copies some library code into each consumer. A union match uses case
numbers. The rules below come from the proof runner in scripts/. Each rule
names its proof case in scripts/proof/cases/.
To stop type inference from changing a signature, use
fsharp-signature-files. This skill does not
repeat it.
Rules
-
Do not add a parameter to a public
letfunction. The compiled static method
gets a new signature, and an old app getsMissingMethodException. Add a new
function and keep the old one as a wrapper (module-parameter):let parsePriceIn (currency: string) (text: string) = ... let parsePrice (text: string) = parsePriceIn "USD" textA rebuilt caller can still compile after the break:
parsePrice textbecomes a
partial application, and%Aprints a function value. -
On a type member, add an overload. A new optional parameter (
?currency)
keeps source compatibility, but it replaces the old method, and an old app gets
MissingMethodException(member-optional). Keep the old member and add a
secondstatic memberor method with the new parameter. The new overload must not
make an existing call ambiguous.Send(Uri)besideSend(string)makes C#
Send(null)fail with CS0121 and an unannotated F# call fail with FS0041.
fsharp-library-api-design proves these
results and gives the call shapes to test. -
Write explicit types on each public function, or use a
.fsifile. A body
change can change the inferred signature, for exampleintto'a, orseqto
list. Each one givesMissingMethodException(infer-generic,
infer-collection). -
Add a union case only at the end. A case in the middle changes the tag number
of each later case. An old app then runs the wrong match branch, with no error
(union-insert). Package validation andapicompatdo not report it. A small
union with case fields kept working in the proof (union-insert-small), but do
not depend on that. -
Do not return a new union case to an old app. An old app that gets an unknown
case runs a wrong branch of its match, with no error. A rebuilt app gets warning
FS0025 andMatchFailureException(union-new-case). When an old app can get the
new case from an existing function, for example because it already passes the new
input, keep that function on the old cases and add a new function that can return
the new case. Otherwise, make a major version. An existing function can return the
new case only when no old app can get it. -
Do not add a field to a public record that callers construct. Record
construction and copy-and-update ({ r with ... }) call the record constructor,
and an old app getsMissingMethodException(record-field,record-copy). A record cannot
keep its old constructor:newin a record gives FS0871. Put the new data in a
new type, for example{ Line: OrderLine; Note: string option }, with new
functions. -
Treat
inlinebodies and[<Literal>]values as copied into each app. An old
app keeps the old body or value until it is rebuilt (inline-body,
literal-value). Use a plain function and a plainletvalue when the body or
value can change, and build the library with the rule 8 flag. With default flags,
a Release app also copies a plainletvalue and keeps the old value
(literal-value,plain-default). -
Know that Release builds also copy small non-inline functions. 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 app then keeps the old body (body-inlined). C#
consumers do not copy bodies. A copied body can also call a changed member: an app
that only called a smalllinefactory gotMissingMethodExceptionfor the
record constructor (record-inlined). A library that must take body changes
with no consumer rebuild needs--nooptimizationdatafrom its first release:<OtherFlags>$(OtherFlags) --nooptimizationdata</OtherFlags>The flag does not change apps that were compiled against an earlier DLL that had
optimization data (body-inlined,safe from v1). It also stops cross-assembly
inlining, so consumer code can be slower.inlinefunctions are still copied
with the flag. -
Rename with a wrapper. In a minor release, add the new name and keep the old
name as a plain wrapper (rename). Mark the old name[<Obsolete("Use X.")>]only
in a major version, and name it in the release notes. A new[<Obsolete>]on an
existing member is a source break: a rebuilt caller gets warning FS0044, and a
consumer withTreatWarningsAsErrorsfails (rename, variantobsolete). Old
binaries still run.[<CompiledName("oldName")>]on the renamed function keeps old
apps working, but each F# caller that is rebuilt gets FS0039. -
Do not change between curried and tupled parameters. Both forms compile to
the same method, so an old app keeps working, but a rebuilt F# caller fails
(curried-tupled).apicompatdoes not report it. Add a new function instead. -
Do not raise the FSharp.Core dependency in a minor release. By default the
package depends on the FSharp.Core version of the SDK that packed it, for
example 10.1.403. A consumer that references a lower FSharp.Core gets only warning
NU1605. It builds, and then fails at startup withFileNotFoundExceptionfor
FSharp.Core, Version=10.1.0.0. Set the lowest version that the library needs:<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference> ... <PackageReference Include="FSharp.Core" Version="8.0.400" /> -
Do not add an abstract member to a public interface. An old app that
implements the interface getsTypeLoadException, and a rebuilt one gets FS0366
(interface-member). Add a new interface that inherits the old one, and test for
it with:?where you need the new member.
Read references/RULES.md for each break with its safe form and
its measured result.
Steps
-
Keep the baseline. Before the change, find the released version: a git tag, a
release folder, or the published package. Build it and keep its DLL. -
Make the change with the rules above. Done when no public
letfunction has a
new parameter, no union case moved, no constructed record has a new field, and no
public interface has a new abstract member. -
Run package validation or
apicompat. Package validation runs indotnet pack:<EnablePackageValidation>true</EnablePackageValidation> <PackageValidationBaselineVersion>1.0.0</PackageValidationBaselineVersion>Restore must find the baseline package on a feed. With package source mapping in
anuget.config, map the package ID to that feed, or restore gives NU1101. For a
baseline that is not packed, compare the DLLs with theapicompattool. The left
side is the baseline:dotnet tool install Microsoft.DotNet.ApiCompat.Tool --create-manifest-if-needed dotnet apicompat --left <baseline>/Lib.dll --right <new>/Lib.dllThe skill's
scripts/.config/dotnet-tools.jsonpins version 10.0.403. Run
dotnet tool restoreinscripts/to use it from there.Both tools fail with
CP0002for a removed or changed member. Fix eachCP0002. -
Run the F# signature diff. It shows the changes that the IL tools do not
report: union case order, curried and tupled parameters,[<Literal>]values,
and inferred types. From the skill root:pwsh ./scripts/sig-diff.ps1 -Project <path>/Lib.fsproj -BaselineRef v1.0.0 pwsh ./scripts/sig-diff.ps1 -Project <path>/Lib.fsproj -BaselineProject <baseline>/Lib.fsprojExit code 0 means no signature change, 1 means a change (the diff is printed), and
2 means a build or checkout failure. The script builds the current project in
place. It checks out-BaselineRefin a temporary folder next to the repository,
so MSBuild, NuGet, andglobal.jsonfiles above the repository apply to both
builds. Pass-Framework <tfm>for a multi-target project. Check each changed line
against the rules.
An added line is safe only when it adds a function, adds a member to a type that
old apps do not implement, or adds a union case after the last case. -
Run an old app against the new DLL. Build a small consumer against the
baseline DLL in Release. Copy the new library DLL into its output folder, with no
rebuild, and run it. It must give the same output for the old cases, with no
MissingMethodException,TypeLoadException, orMissingFieldException. No
tool finds copied bodies or behavior changes. Only this run does. -
Rebuild the consumers against the new version and test the new features.
-
For an accepted break, make a major version. A new
[<Obsolete>]on an
existing member also needs a major version, and the release notes must name it.
Record each binary break inCompatibilitySuppressions.xml.
dotnet pack -p:ApiCompatGenerateSuppressionFile=truewrites the file next to the
project, and later packs read it. Add an XML comment with the reason above each
suppression.
Tools
| Tool | Use it | Reports | Does not report |
|---|---|---|---|
| Package validation | Yes, in the build | Removed or changed members (CP0002) | Union case order, copied bodies. From the apicompat results, also [<Literal>] values and curried and tupled changes |
apicompat | Yes, for DLLs that are not on a feed | The same as package validation. --strict-mode also reports each added member. | The same as package validation, also with --enable-rule-attributes-must-match |
sig-diff.ps1 | Yes, after package validation | The F# view: case order, curried and tupled, literals, inferred types | Body changes, also in inline functions |
| PublicApiGenerator snapshot | Optional | Each public change, also the union, literal, and curried-to-tupled changes. Also each addition that does not break. | Body changes |
Microsoft.CodeAnalysis.PublicApiAnalyzers | No | Nothing in F#: the F# compiler does not run Roslyn analyzers | Everything |
Read references/TOOLS.md for the measured result of each tool
on each proof case.
Verify
Run the proof runner from the skill root:
pwsh ./scripts/run.ps1
For each case, the runner builds the library versions and a consumer against the
baseline. It runs the old consumer with the new DLL, rebuilds the consumer, and runs
apicompat, apicompat --strict-mode, the signature diff, and PublicApiGenerator. It
fails when a result differs from the // expect line in the case's Consumer.fs.
It then checks package validation, the FSharp.Core dependency, the Roslyn analyzer
claim, and sig-diff.ps1. Use -Case <name> to run only some cases. With -Case,
the runner does not run these tool proofs.
Two statements in rule 8 are not proofs of this runner. The copy through a
ProjectReference comes from a test with SDK 10.0.404. The C# result comes from the
SmallFunctionBodyChange proof of
fsharp-library-api-design.
Security
Reviews (0)
Related skills
Browse all →More from F# Skills
View source →More Build skills
Browse category →Frequently asked questions about fsharp-binary-compatibility
What does the fsharp-binary-compatibility skill do?
Change 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. 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-binary-compatibility skill?
Run `npx @skills-hub-ai/cli install fsharp-skills-fsharp-binary-compatibility` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/fsharp-skills-fsharp-binary-compatibility/ 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-binary-compatibility work with?
fsharp-binary-compatibility 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-binary-compatibility 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-binary-compatibility after installing it?
In Claude Code, type `/fsharp-skills-fsharp-binary-compatibility` (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-binary-compatibility 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.