fsharp-iwsam-errors
Skill23 starsChanged 32 days agoMITView on GitHub
Design 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.
In this repository16 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- fsharp-async-compositionSkill
- fsharp-binary-compatibilitySkill
- fsharp-env-capabilitiesSkill
- fsharp-failure-pathsSkill
- fsharp-idiom-reviewSkill
- fsharp-library-api-designSkill
- fsharp-native-aotSkill
- fsharp-nullness-interopSkill
- fsharp-performance-typesSkill
- fsharp-serializationSkill
- fsharp-signature-filesSkill
- fsharp-verify-apiSkill
- optimize-fsharp-typecheck-graphSkill
- parse-dont-validateSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 23
Put #nowarn "3535" at file top, or pass --nowarn:3535 to dotnet fsi.
- Very specific: line 57
Write composites as plain result blocks with do!
- Very specific: line 79
Run scripts/run.ps1. It runs Domain.fsx, Shapes.fsx, and Effects.fsx, prints the inferred signatures, and confirms that each script under …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
F# IWSAM error trees
A leaf function declares its errors as an interface with static abstract members and returns
Result<_, 'e> when 'e :> LeafError<'e>. Composites in a result block pick up the union of
their leaves' constraints with no Result.mapError. The caller at the edge picks one concrete
type that implements every interface the tree needs. The gist that started this:
https://gist.github.com/TheAngryByrd/ceb18e5b219458084f6c156b538ba579. A runnable proof with
seven edge shapes and four compile-time break tests lives in scripts/. Read
references/FINDINGS.md for output you can compare against.
Rules
- A payload is a typed value. A
stringappears in an error only when it comes from outside the domain: the raw input that failed to parse, namedraw, or a message an external library or call returned, named for its source. - A domain value with a format rule gets a private constructor and a
parsefunction. Thatparseis itself a leaf. - One interface per source of failure. Name the parse leaf after the failure:
InvalidSku,UnparsedEmail. - A bundle interface that inherits several leaves is implementer convenience. Inference never names it. Add one only when several edge types implement the same set.
- Put
#nowarn "3535"at file top, or pass--nowarn:3535todotnet fsi. The in-file directive does not silence the main script underdotnet fsi. - A leaf that also takes a capability env as
#IProvideXmust name'envin its explicit type parameters:<'env, 'e when 'env :> IProvideX and X<'e>>. Thefsharp-env-capabilitiesskill records theFS0064failure.
Steps
- List every function that returns
Result. For each, write the cases it alone can produce, with typed payloads. Done when no case carries astringexcept arawinput or an external library's message. Declare one IWSAM per function or per domain value parser:
type StockError<'e> = static abstract OutOfStock : sku: Sku -> 'e static abstract Discontinued : sku: Sku -> 'e let reserveStock<'e when StockError<'e>> onHand (line: OrderLine) : Result<unit, 'e> = match Map.tryFind line.Sku onHand with | None -> Error('e.Discontinued line.Sku) | Some n when n < line.Quantity -> Error('e.OutOfStock line.Sku) | Some _ -> Ok()Done when every leaf has the explicit
<'e when X<'e>>and return annotation. Without it,'e.Memberfails withFS0039: The type parameter 'e is not defined.Give each parsed value a private case and a generic
parse:type Sku = private Sku of string module Sku = let value (Sku s) = s let parse<'e when SkuError<'e>> (raw: string) : Result<Sku, 'e> = if isValid raw then Ok(Sku raw) else Error('e.InvalidSku raw)Done when
Sku "x"outside the module fails withFS1093.- Write composites as plain
resultblocks withdo!andlet!. Add no annotation and nomapError. Done whendotnet fsiprints the composite's signature with the union of leaf constraints and nothing else. - Pick the edge shape from references/SHAPES.md and implement every interface the composite's signature names. Done when the edge compiles and the handler matches exhaustively on it.
- Fix the edge at each call site with a result annotation or a concrete-case match.
Done when no call site reports
FS0331. - Where two calls to one leaf must be told apart, wrap that call alone with
Result.mapError. Done when the handler can name the call site for every such pair.
Compiler signals
| Error | Meaning | Action |
FS0366: No implementation was given for 'static abstract ...' | A leaf gained a case and this edge misses it. | Add the member. This is the safety the approach buys. |
FS0331: The implicit instantiation of a generic construct ... could not be resolved | Nothing fixes 'e at this call. | Annotate the result or match a concrete case. |
FS0001: The type 'X' is not compatible with the type 'Y<X>' | The edge misses interface Y. The message names the first missing one only. | Implement Y, compile again. |
FS1093: The union cases or fields of the type 'X' are not accessible | Code bypassed parse. | Call X.parse. |
FS0039: The type parameter 'e is not defined | A leaf uses 'e.Member without the explicit constraint. | Add <'e when X<'e>> to the function. |
| Two records share a field name and the wrong one is inferred | F# picks the last declared record. | Annotate the record expression. |
Verify
Run scripts/run.ps1. It runs Domain.fsx, Shapes.fsx, and Effects.fsx,
prints the inferred signatures, and confirms that each script under scripts/breaks/ fails with
the error quoted above. Keep a breaks/ folder in your own project for the same reason. A break
test is the only evidence that a new leaf cannot reach a handler unseen.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

