fsi

GitHub

提供 F# Interactive (FSI) 交互式编程与脚本执行能力,支持 .fsx 脚本、NuGet 引用及快速类型探索。适用于实验性验证和一次性数据转换,不用于生产代码。

catalog/Tools/FSharp/skills/fsi/SKILL.md managedcode/dotnet-skills

Trigger Scenarios

需要 F# Interactive 或 REPL 环境 使用 .fsx 文件进行脚本化实验 通过 #r nuget 引用包 进行快速类型推断或管道处理测试

Install

npx skills add managedcode/dotnet-skills --skill fsi -g -y
More Options

Non-standard path

npx skills add https://github.com/managedcode/dotnet-skills/tree/main/catalog/Tools/FSharp/skills/fsi -g -y

Use without installing

npx skills use managedcode/dotnet-skills@fsi

指定 Agent (Claude Code)

npx skills add managedcode/dotnet-skills --skill fsi -a claude-code -g -y

安装 repo 全部 skill

npx skills add managedcode/dotnet-skills --all -g -y

预览 repo 内 skill

npx skills add managedcode/dotnet-skills --list

SKILL.md

Frontmatter
{
    "name": "fsi",
    "description": "Use F# Interactive (`dotnet fsi`) for .NET exploration, scriptable experiments, package-backed .fsx workflows, quick data transforms, and reproducible command-line probes. USE FOR: .fsx scripts, F# REPL work, #r nuget references, #load composition, interactive type exploration, and small strongly typed experiments before moving code into a project. DO NOT USE FOR: production application code that needs compiled project structure; C# scripting; long-lived automation better expressed as a normal CLI, test, or build target. INVOKES: run dotnet fsi, edit .fsx scripts, load project or source files, and validate snippets against the target SDK.",
    "compatibility": "Requires a .NET SDK with `dotnet fsi`; NuGet-backed scripts may need package restore and trusted package sources."
}

F# Interactive

Trigger On

  • the task asks for F# Interactive, FSI, .fsx, or dotnet fsi
  • a quick typed experiment is needed before changing compiled project code
  • a script should reference NuGet packages directly with #r "nuget: ..."
  • an investigation needs quick access to F# type inference, pattern matching, or pipelines
  • a repeatable one-file probe is better than a temporary project

Do Not Use For

  • long-lived application code that needs a compiled .fsproj
  • production automation that should be versioned as a CLI, test project, or build target
  • C# script work
  • package restore from untrusted sources

Quick Start

Run an interactive REPL:

dotnet fsi

Run a script:

dotnet fsi scripts/check.fsx

Create a Unix executable script when that fits the repo:

#!/usr/bin/env -S dotnet fsi

printfn "Hello from FSI"
chmod +x scripts/check.fsx
./scripts/check.fsx

On Windows, run scripts with dotnet fsi scripts/check.fsx.

Workflow

  1. Decide whether the request is a disposable REPL probe, a repeatable .fsx script, or code that should be promoted to a compiled F# project.
  2. Put repeatable work in an .fsx file immediately. Add all required #r, #load, open, input path, and package source directives to the script instead of relying on hidden REPL state.
  3. Keep package references pinned when the script should be reproducible, and use only trusted NuGet feeds or local feeds derived from __SOURCE_DIRECTORY__.
  4. Run the script with dotnet fsi from a clean shell, passing the same arguments the user or CI will use.
  5. Promote the script to an .fsproj when it needs tests, distribution, project references, or long-term CI coverage.

Current Upstream Notes

  • The August 2026 F# Interactive reference keeps dotnet fsi as the supported command-line entry point for interactive sessions and .fsx scripts; it does not turn hidden REPL state into a reproducible workflow.
  • Use repeatable .fsx files with explicit #r "nuget: ..." and #load directives once an experiment affects a repository task; do not rely on hidden REPL state.

Interactive Session Rules

  • End REPL submissions with ;;.
  • Multi-line input is allowed; FSI evaluates when it receives ;;.
  • Previously evaluated values stay in the session, so do not rely on hidden session state in scripts.
  • Use .fsx files for repeatability once an experiment matters.
let square x = x * x;;

[ 1 .. 5 ] |> List.map square;;

Script Patterns

Read And Summarize Text

Use ordinary .NET APIs directly from F# scripts.

open System
open System.IO

let summarize path =
    File.ReadLines path
    |> Seq.filter (String.IsNullOrWhiteSpace >> not)
    |> Seq.countBy (fun line -> line.Split(' ')[0])
    |> Seq.sortByDescending snd
    |> Seq.truncate 10
    |> Seq.toList

for key, count in summarize "input.log" do
    printfn $"{key}: {count}"

Write A Checked Output File

Keep script outputs deterministic and fail early when required inputs are missing.

open System
open System.IO

let input = "data/items.txt"
let output = "artifacts/items.normalized.txt"

if not (File.Exists input) then
    failwith $"Missing input file: {input}"

Directory.CreateDirectory(Path.GetDirectoryName output) |> ignore

File.ReadLines input
|> Seq.map (fun line -> line.Trim())
|> Seq.filter (String.IsNullOrWhiteSpace >> not)
|> Seq.distinct
|> Seq.sort
|> fun lines -> File.WriteAllLines(output, lines)

Reference NuGet Packages

Pin package versions for repeatable scripts. Only use package sources the repo trusts.

#r "nuget: Newtonsoft.Json, 13.0.3"

open Newtonsoft.Json

let payload = {| Name = "Ada"; Kind = "sample" |}
let json = JsonConvert.SerializeObject(payload)

printfn $"{json}"

Use #i only when an additional feed is required. Local feed paths must be absolute; construct them from __SOURCE_DIRECTORY__ instead of committing personal paths.

let localFeed =
    System.IO.Path.Combine(__SOURCE_DIRECTORY__, "../artifacts/packages")
    |> System.IO.Path.GetFullPath

#i $"nuget: {localFeed}"

Split Scripts With Load

#load evaluates another script and exposes it through the generated module name.

// MathHelpers.fsx
let square x = x * x
// Check.fsx
#load "MathHelpers.fsx"
open MathHelpers

printfn $"%d{square 12}"

Promote To A Project

Move from FSI to a compiled project when:

  • the script has multiple dependencies, tests, or distribution needs
  • startup time or restore behavior matters
  • C# or other .NET callers need a stable assembly
  • the code needs CI coverage beyond a smoke run

Start with:

dotnet new console -lang "F#" -o tools/Probe
dotnet build tools/Probe/Probe.fsproj

Validate

Use the simplest command that proves the script still runs:

dotnet fsi scripts/check.fsx
dotnet fsi scripts/check.fsx -- arg1 arg2

For scripts that reference packages, run from a clean shell at least once so hidden REPL state cannot mask missing #r, #load, or open directives.

Sources

Version History

  • 0559476 Current 2026-08-19 23:38

    同步上游 2026-08 版本的 F# Interactive 参考说明,更新关于 dotnet fsi 命令行入口及可重复工作流的最佳实践。

  • 7ab7f03 2026-07-25 05:26

Same Skill Collection

catalog/Frameworks/gRPC/skills/grpc/SKILL.md
catalog/Frameworks/Official-Astro/skills/astro-developer/SKILL.md
catalog/Frameworks/Official-DotNet-ASPNetCore/skills/configuring-opentelemetry-dotnet/SKILL.md
catalog/Frameworks/Official-DotNet-ASPNetCore/skills/dotnet-webapi/SKILL.md
catalog/Frameworks/Official-DotNet-ASPNetCore/skills/minimal-api-file-upload/SKILL.md
catalog/Frameworks/Orleans/skills/orleans/SKILL.md
catalog/Frameworks/ThreeJS-WebGPU-TSL/skills/webgpu-threejs-tsl/SKILL.md
catalog/Libraries/Official-DotNet-Data/skills/optimizing-ef-core-queries/SKILL.md
catalog/Platform/Official-DotNet-Advanced/skills/csharp-scripts/SKILL.md
catalog/Platform/Official-DotNet-Advanced/skills/nuget-trusted-publishing/SKILL.md
catalog/Platform/Official-DotNet-Blazor/skills/create-blazor-project/SKILL.md
catalog/Platform/Official-DotNet-Blazor/skills/fetch-and-send-data/SKILL.md
catalog/Platform/Official-DotNet-Blazor/skills/support-prerendering/SKILL.md
catalog/Platform/Official-DotNet-Blazor/skills/use-js-interop/SKILL.md
catalog/Platform/Official-DotNet-Experimental/skills/exp-mock-usage-analysis/SKILL.md
catalog/Platform/Official-DotNet-Experimental/skills/exp-simd-vectorization/SKILL.md
catalog/Platform/Official-DotNet-Test-Migration/skills/migrate-xunit-to-mstest/SKILL.md
catalog/Platform/Official-DotNet-Test-Migration/skills/migrate-xunit-to-xunit-v3/SKILL.md
catalog/Platform/Official-DotNet-Upgrade/skills/dotnet-aot-compat/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/code-testing-extensions/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/filter-syntax/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/find-untested-sources/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/platform-detection/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/scaffold-dotnet-test-project/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/test-gap-analysis/SKILL.md
catalog/Testing/Official-DotNet-Test/skills/testability-obstacle/SKILL.md
catalog/Testing/Playwright/skills/playwright-visual-testing/SKILL.md
catalog/Testing/xUnit/skills/xunit/SKILL.md
catalog/Tools/Code-Analysis/skills/code-analysis/SKILL.md
catalog/Tools/HTMLHint/skills/htmlhint/SKILL.md
catalog/Tools/Official-DotNet-Diagnostics/skills/analyzing-dotnet-performance/SKILL.md
catalog/Tools/Official-DotNet-Diagnostics/skills/clr-activation-debugging/SKILL.md
catalog/Tools/Official-DotNet-Diagnostics/skills/dotnet-trace-collect/SKILL.md
catalog/Tools/Official-DotNet-Diagnostics/skills/dump-collect/SKILL.md
catalog/Tools/Official-DotNet-MSBuild/skills/binlog-failure-analysis/SKILL.md
catalog/Tools/Official-DotNet-MSBuild/skills/copy-to-output-directory/SKILL.md
catalog/Tools/Official-DotNet-MSBuild/skills/msbuild-server/SKILL.md
catalog/Tools/Official-DotNet-MSBuild/skills/resolve-project-references/SKILL.md
catalog/Tools/ReportGenerator/skills/reportgenerator/SKILL.md
catalog/Tools/ReSharper-CLT/skills/resharper-clt/SKILL.md
catalog/Tools/Roslynator/skills/roslynator/SKILL.md
catalog/Tools/Stylelint/skills/stylelint/SKILL.md
external-sources/upstreams/webgpu-claude-skill/skills/webgpu-threejs-tsl/SKILL.md
catalog/Frameworks/ASP.NET-Core/skills/aspnet-core/SKILL.md
catalog/Frameworks/Aspire/skills/aspire/SKILL.md
catalog/Frameworks/Azure-Functions/skills/azure-functions/SKILL.md
catalog/Frameworks/Blazor/skills/blazor/SKILL.md
catalog/Frameworks/Entity-Framework-6/skills/entity-framework6/SKILL.md
catalog/Frameworks/Entity-Framework-Core/skills/entity-framework-core/SKILL.md
catalog/Frameworks/MAUI/skills/maui/SKILL.md

Metadata

Files
0
Version
0559476
Hash
df4a9c6c
Indexed
2026-07-25 05:26

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-21 20:29
浙ICP备14020137号-1 $mapa de visitantes$