fsharp-csharp-interop
БесплатноБез исполняемых скриптовНе проверенRules for F# code that C# calls, and C# code that calls F#, in morphir-dotnet. Covers parsed domain types, nullness metadata, TryParse/Create members, Match…
от finos★ 15 звёзд на GitHubОб этом скилле
F# and C# interop
morphir-dotnet writes domain types in F# and keeps the CLI edge in C# where C# is required (System.Text.Json source generation, System.CommandLine, Foundatio.Mediator). This skill holds the rules for the boundary between the two languages.
The rules apply only to the C# surface: the F# types, members and modules that a C# project calls. Inside F#, write idiomatic F#.
Code examples for each rule are in references/patterns.md. Read that file before you write new boundary code.
Before you start
- Find the C# surface. List the F# types and members that a C# project uses. Search the
.csfiles for the F# namespace. - Decide where each decision lives. A decision that branches on an F# union goes in an F# function. C# calls that function and does not branch.
- Check the project settings (rule 1). Without them, the C# compiler cannot see F# nullness.
Rules
1. Project settings
Every F# project that C# references sets:
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsTrimmable>true</IsTrimmable>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<IsAotCompatible>true</IsAotCompatible>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Nullable>enable</Nullable> makes F# write nullable metadata. Without it, C# treats every F# reference type as "oblivious" and gives no warning when it passes null. The C# projects already set <Nullable>enable</Nullable> and treat warnings as errors.
2. Parse, don't validate
- A domain value with a rule (an id, a name, a version, a target) is a single-case union with a private case, or a record with a private representation. Only its own module can build it.
- Give it
static member Parse(text) : Result<T, ParseFailure>for F# callers,static member TryParse(text, out result, out failure) : boolfor C# callers, andstatic member Create(literal)for literals in source code.Createthrows on invalid text. A unit test callsCreatefor each literal. - A record with an invariant must not have a public constructor. C# can call a public F# record constructor and skip every rule.
- Never use
[<Struct>]for a parsed value.default(T)skips the parser. - Derive dependent facts. Do not store a value that another value already decides (for example, entry types that come from capability claims).
3. Names and calls
- Put the C# surface on types as static or instance members. Use
[<CompiledName("PascalCase")>]when a module function must be called from C#. - Use tupled parameters on members. Never put an F# function type (
'a -> 'b) in a C# parameter or return type. UseFunc<...>orAction<...>. - Put the code in a
namespace, not in a top-level module, and use[<RequireQualifiedAccess>]on unions and modules. - Return
Task<T>orValueTask<T>and take aCancellationToken. Never returnAsync<'T>to C#. - C# cannot use
withon an F# record. Where C# must change one field, give the record aWith...member (for exampleWithHosts). - In C#,
==and!=on an F# union or record compare references, because F# defines no C# equality operators. Compare withEquals.
4. Nullness
- On the C# surface, an absent value is
T | null. Inside F#, it isoption. Convert at the surface withOption.toObjandOption.ofObj. - A parameter that receives text from outside takes
string | null, so C# can pass what it has and the parser decides. TryParseand similar members use a non-nullableouttype with[<Out; MaybeNullWhen(false)>]on the result and[<Out; MaybeNullWhen(true)>]on the failure, and assignUnchecked.defaultof<_>to the one that is not set. C# flow analysis then knows which one is set.- Do not write
byref<T | null>for anoutvalue. F# does not write the nullness of a byref element into the metadata, so C# reads the value as never null and gives no warning when code reads it on the wrong branch. - Nullness checks are compile-time only.
null!, reflection and deserialization can still putnullinto a value. Parse at every real input boundary.
5. Unions seen from C#
- Prefer an F# function that makes the decision. C# then calls it and never branches on the union.
- When C# must branch, add a
Matchmember with oneFuncfor each case. The signature forces C# to handle every case. Do not ask C# to useTag,IsXor type tests. - C# builds a fieldless case through the generated static property (
MorphirHost.Native). For a case with fields, give C# a named factory member when it needs one. - When C# must write a union as text, give the union a
WireValuemember. C# reads it and does not map cases by hand.
6. Collections
- On the C# surface, use
IReadOnlyList<T>,IReadOnlyCollection<T>,ImmutableArray<T>or a project type such asNonEmptySet<T>. - Never expose F#
list,Set,Maporseqthat C# must enumerate more than once.
7. Equality, order and text
- Us
Установить fsharp-csharp-interop в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл fsharp-csharp-interop?
Rules for F# code that C# calls, and C# code that calls F#, in morphir-dotnet. Covers parsed domain types, nullness metadata, TryParse/Create members, Match members for unions, collections, option and null, equality, ToString and AOT safety, and the .fsproj settings. Use when you add or change a public F# type, member or module that a C# project uses; when C# code calls F# types (unions, records, Result, option, list); when you create an F# project that C# references; or when you review a diff that crosses the F#/C# boundary. Triggers include "F# interop", "C# interop", "call F# from C#", "F# union in C#", "MaybeNullWhen", "NotNullWhen", "CompiledName", "F# nullness", "Nullable enable fsproj", "oblivious", "TryParse", "parse don't validate".
Как установить скилл fsharp-csharp-interop?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл fsharp-csharp-interop запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic