fsharp-env-capabilities
Pass 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.
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-env-capabilitiesManual setup by platform
Claude Code
~/.claude/skills/fsharp-skills-fsharp-env-capabilities/SKILL.md
Instructions
F# environment capabilities
Each function takes env as its first parameter. A capability is an interface with one property
that exposes a worker interface. A function names only the capabilities it uses, through a
flexible type #IProvideX. A composite that calls several functions gets the union of their
capabilities by inference, with no new parameter. The caller passes one object that implements
every capability the call tree names. Sources: Bartosz Sypytkowski,
Dealing with complex dependency injection in F#,
and the bridge to ASP.NET Core DI, Fsharp-DI-Bridge.
A runnable proof with a test env, a container env, and two compile-time break tests lives in
scripts/. Read references/FINDINGS.md for output you can
compare against.
Rules
- Two interfaces per capability. The worker holds the operations, for example
ILogger. The accessor holds one property, for exampleIProvideLoggerwithabstract Logger: ILogger. Name accessorsIProvideX. The env implements accessors only. references/ENV-PATTERNS.md gives the reasons. - The accessor exposes a worker interface or a plain value, never a concrete class such as
RandomorHttpClient. A test must control what the worker returns. Wrap the class:IRandomwithNextBytes: length: int -> byte[], implemented once bySystemRandomand in tests byFixedRandom. - One module per capability. Each function takes
(env: #IProvideX)first and readsenv.X. - A composite leaves
envunannotated. Inference supplies the union. - A function that declares explicit type parameters must name
'envamong them. SeeFS0064below. - A bundle interface that inherits several
IProvideXis for implementers: the production env, a test requirements type. Inference never names it. - Keep
taskandtaskResultblocks. The Reader-monad variant in the article drops async composition. The article itself rates it less useful.
Steps
-
List the external things a function touches: logging, database, clock, random, configuration, cache. Each is one capability.
Done when every I/O call in the function maps to one capability and each worker is an interface a test can fake. -
Declare the worker and accessor pair and the module:
type ILogger = abstract Info: string -> unit type IProvideLogger = abstract Logger: ILogger module Log = let info (env: #IProvideLogger) fmt = Printf.kprintf env.Logger.Info fmtDone when
dotnet fsiprintsval info: env: #IProvideLogger -> .... -
Write leaves with
(env: #IProvideX). When a leaf also declares'efor an IWSAM error, declare'envexplicitly:let fetchUser<'env, 'e when 'env :> IProvideDatabase and UserError<'e>> (env: 'env) (id: int) : Task<Result<User, 'e>> =Done when
dotnet fsiprints nowarning FS0064for the leaf. -
Write composites with
envunannotated and passenvto each call:let changePassword env (request: ChangePasswordRequest) = taskResult { let! user = Db.fetchUser env request.UserId do! Db.updateUser env { user with Salt = Random.salt env 16 } Log.info env "password changed for %d" user.Id }Done when the printed signature shows the union, for example
when 'a :> IProvideDatabase and 'a :> IProvideLogger and 'a :> IProvideRandom. -
Build the production env and the test env from references/ENV-PATTERNS.md.
Done when the same composite runs with both and the test env implements only the capabilities the composite names. -
Add a
breaks/script that passes an env with one capability missing.
Done when it fails withFS0193.
Compiler signals
| Signal | Meaning | Action |
|---|---|---|
FS0193: The type 'LogOnly' is not compatible with the type 'IProvideClock' | The env misses a capability the call tree names. | Implement IProvideClock on the env. |
warning FS0064: ... The type variable implied by the use of a '#' ... has been constrained to be type 'FirstEnv' | A function with explicit type parameters used #IProvideX. The compiler did not generalize env. The first caller fixed it. A second caller then fails with FS0193: The type 'SecondEnv' is not compatible with the type 'FirstEnv'. | Name 'env in the explicit list: <'env, 'e when 'env :> IProvideX and ...>. |
Signature prints IProvideDatabase -> ... instead of 'a -> ... when 'a :> IProvideDatabase | The function uses one capability. The compiler fixed env to that interface. | No action. Any env that implements it still passes. A composite that calls it still infers the full union. |
FS0039: The type parameter 'e is not defined | A composite named an IWSAM member. | Move the check into a leaf. See the fsharp-iwsam-errors skill. |
Settings
Settings are one more capability. Bind configuration to a DTO, parse the DTO into a validated
type at startup, and expose that type through an accessor.
references/SETTINGS.md has the full example and the binder table.
scripts/Settings.fsx checks each rule below.
- Bind to a
[<CLIMutable>]DTO that only the composition root reads. A missing key gives no error: anintbinds as0and astringasnull. - In the DTO, use
stringfor a number and convert it in the parser. Then text that does not convert is one more error. ANullable<int>orintfield throws in the binder on such text, before the parser runs. Usestring[]for a list. Astring listfield throws when the key is present. Astring optionfield isNoneeven when the key has a value. section.Get<Dto>()returnsnullfor a missing section.AddOptions<Dto>().Bind(section)gives an instance with default fields. A missing nested record binds asnullin both forms.- Parse the DTO with
parse: Dto -> Result<Settings, SettingsError list>, whereSettingsErroris a union with one case for each failure. Usevalidation { let! ... and! ... }so that the result holds every error. Make the message text only at the edge, such asIValidateOptions, and name the configuration key in it. For the parsed type, use theparse-dont-validateskill. - Stop the app before it does work. Either parse in the composition root and stop on
Error, or register anIValidateOptions<Dto>that calls the parser and add.ValidateOnStart(). ValidateOnStartruns only when a host starts. WithValidateOnStartand a bareServiceCollection, callprovider.GetRequiredService<IStartupValidator>().Validate(). Otherwise the error comes at the first read.Validate()throwsOptionsValidationExceptionfor one bad section andAggregateExceptionfor two or more. Catch both, or the error list is lost.- Expose the parsed type through one accessor for each section:
IProvideMailSettingswithabstract MailSettings: MailSettings. No function outside the composition root takesIOptions<T>orIConfiguration. - A test env returns a settings record literal. It needs no configuration, no container, and no
Options.Create.
Verify
Run scripts/run.ps1. It runs Environment.fsx, FlatEnv.fsx, and Settings.fsx,
and prints the inferred signatures. It fails when a Settings.fsx check does not match. It also checks that each script under scripts/breaks/ fails with the error
quoted above. In your own project, print the signature of every composite with dotnet fsi and
read the constraint list. A composite whose signature names a concrete env type has lost its
genericity. Find the leaf that pinned it.
Security
Reviews (0)
Related skills
Browse all →More from F# Skills
View source →More Build skills
Browse category →Frequently asked questions about fsharp-env-capabilities
What does the fsharp-env-capabilities skill do?
Pass 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. 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-env-capabilities skill?
Run `npx @skills-hub-ai/cli install fsharp-skills-fsharp-env-capabilities` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/fsharp-skills-fsharp-env-capabilities/ 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-env-capabilities work with?
fsharp-env-capabilities 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-env-capabilities 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-env-capabilities after installing it?
In Claude Code, type `/fsharp-skills-fsharp-env-capabilities` (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-env-capabilities 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.