fsharp-signature-files
Add 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.
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-signature-filesManual setup by platform
Claude Code
~/.claude/skills/fsharp-skills-fsharp-signature-files/SKILL.md
Instructions
F# signature files
A .fsi file is the contract of its .fs file. A value or type that is not in the
.fsi is hidden from every later file and every other assembly. A type that the .fsi
declares with no body (type Email) hides its fields and cases.
The compiler can write a .fsi for you, but that output repeats every public member.
It hides nothing. The work is to remove what callers do not use.
Build time can also improve. Later files type-check against the .fsi, not the
.fs, so graph-based type checking can check them in parallel with the implementation.
Measure this before you claim a speed-up. See
optimize-fsharp-typecheck-graph.
Steps
-
Record the public surface before the change. Build the library and run:
pwsh ./scripts/public-surface.ps1 -Assembly <bin>/<Lib>.dll -OutFile before.txt -
Generate a starting point. Build once with
--allsigs. It writes one.fsi
next to each.fs, with doc comments and attributes:dotnet build <Lib>.fsproj -p:OtherFlags=--allsigsBuild the library project file, not the solution. The global property also reaches
each project that the library references, and it replaces anOtherFlagsvalue
that the project sets. When the project setsOtherFlags, add--allsigsto that
value for one build instead.--sig:<file>writes all signatures into one file,
which you must then split by hand. Remove the flag after this build. Delete each
.fsithat the build wrote outside the library, and the.fsifiles underobj/
for generated files such asAssemblyAttributes.fs. -
Add each
.fsito the project directly before its.fs:<Compile Include="Email.fsi" /> <Compile Include="Email.fs" />A
.fsiafter its.fsgives FS0238 and FS0248. -
Decide what is truly public. Search the other projects, the tests, and the
documented entry points for each member in the.fsi. Delete eachval, type, and
member that no other project uses. Do not mark itprivatein the.fsinstead: the
omission from the.fsiis the hiding.- A member that only tests use: write
val internal f: ...in the.fsiand add
<InternalsVisibleTo Include="<Tests assembly name>" />to the library project.
Do not make it public for the tests. - The generated
.fsialso listsval privatevalues. Delete them.
- A member that only tests use: write
-
Hide representations where callers must not build values. Replace the record or
union body in the.fsiwith the bare type name and keep the constructor function:/// An email address that contains one '@'. type Email type EmailError = | NotOneAtSign of count: int module Email = val create: input: string -> Result<Email, EmailError> val value: email: Email -> stringCallers then get FS0039 for
{ Value = ... }or a union case. Keep a record public
when every combination of its field values is valid. For the choice of type and
constructor, use parse-dont-validate. -
Fix the traps. Read references/TRAPS.md for the
diagnostics. The most important rules:- Copy each attribute on a type or value to the
.fsi:[<RequireQualifiedAccess>],
[<Struct>],[<Literal>]. Do not add an attribute that the.fsdoes not have:
[<Sealed>]on a class in the.fsionly gives FS0297. A missingRequireQualifiedAccessgives
only warning FS3888. The build passes, and callers can use the cases without the
type name. - Check each string argument of an attribute in the generated
.fsi.--allsigs
and--sigwrite the value between plain quotes, with no escapes. A value with a backslash,
such as@"C:\temp\orders", changes. The build passes with warning FS1200, and the
compiled attribute gets the changed value from the.fsi. A value with a double
quote fails with FS0003. Replace each such argument with the literal from the.fs. - List each implemented interface:
interface System.IDisposable. Without it, you
get warning FS0050, andusein a caller fails with FS0193. - Put XML doc comments in the
.fsi. When a.fsiexists, a doc comment that is
only in the.fsis not in the XML documentation file. - Write each
valwith the same generic arity andinlineflag as the.fs.
- Copy each attribute on a type or value to the
-
Check the result.
- Build every project and run the tests. Treat FS3888 and FS0050 warnings as
errors to fix. - Run
public-surface.ps1again and compare withbefore.txt. Each removed line
must be a member that no caller uses. No line may be added. - Write a small probe file in a consumer that builds a hidden record or union
directly. It must fail to compile. Then delete it.
- Build every project and run the tests. Treat FS3888 and FS0050 warnings as
Verify
Run the bundled proof from the skill root:
pwsh ./scripts/run.ps1
The runner builds scripts/Sample and checks its public surface, its XML
documentation, and an InternalsVisibleTo test project. It builds
scripts/Generate with --allsigs and checks the generated .fsi.
It then builds each folder in scripts/breaks and checks the diagnostic
codes in its // expect: lines.
These rules come from the F# documentation and are not bundled proofs: a val inline
in a .fsi makes the function body part of the contract, so callers must build again
when the body changes. Use inline in a .fsi only when the function needs it, for
example for statically resolved type parameters.
These results come from a test with SDK 10.0.404 and are not bundled proofs. --sig
writes attribute strings in the same form as --allsigs. You can delete an attribute
from the .fsi and keep it in the .fs. Then the DLL keeps the attribute, but F#
callers do not see it. A caller of an [<Obsolete>] value gets no warning FS0044.
So fix a changed string argument. Do not delete the attribute.
Security
Reviews (0)
Related skills
Browse all →More from F# Skills
View source →More Build skills
Browse category →Frequently asked questions about fsharp-signature-files
What does the fsharp-signature-files skill do?
Add 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. 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-signature-files skill?
Run `npx @skills-hub-ai/cli install fsharp-skills-fsharp-signature-files` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/fsharp-skills-fsharp-signature-files/ 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-signature-files work with?
fsharp-signature-files 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-signature-files 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-signature-files after installing it?
In Claude Code, type `/fsharp-skills-fsharp-signature-files` (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-signature-files 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.