F# 交互选项
本文介绍 F# Interactive 支持的命令行选项,fsi.exe
。 F# Interactive 接受与 F# 编译器相同的许多命令行选项,但也接受一些其他选项。
使用 F# Interactive 编写脚本
F# Interactive(dotnet fsi
)可以以交互方式启动,也可以从命令行启动以运行脚本。 命令行语法为
dotnet fsi [options] [ script-file [arguments] ]
F# 脚本文件的文件扩展名 .fsx
。
F# 交互窗口选项表
下表汇总了 F# Interactive 支持的选项。 可以在命令行或 Visual Studio IDE 上设置这些选项。 若要在 Visual Studio IDE 中设置这些选项,请打开 工具 菜单,选择 选项,展开 F# 工具 节点,然后选择 F# Interactive。
如果列表出现在 F# 交互选项参数中,列表元素由分号(;
)分隔。
选项 | 描述 |
---|---|
-- | 用于指示 F# Interactive 将其余参数视为 F# 程序或脚本的命令行参数,可以使用列表 fsi 在代码中访问这些参数。CommandLineArgs。 |
--checked[+|-] | 与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项。 |
--checknulls[+|-] | 与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项。 |
--codepage:<int> | 与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项。 |
--consolecolors[+|-] | 以颜色输出警告和错误消息。 |
**--compilertool:<extensionsfolder> | 引用包含设计时工具的程序集或目录(简短形式:-t)。 |
--crossoptimize[+|-] | 启用或禁用跨模块优化。 |
--debug[+|-] --debug:[full|pdbonly|portable|embedded] -g[+|-] -g:[full|pdbonly|portable|embedded] |
与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项。 |
--define:<string> | 与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项。 |
--确定性[+|-] | 生成确定性程序集(包括模块版本 GUID 和时间戳)。 |
--exec | 指示 F# 交互窗口在加载文件或运行命令行上给定的脚本文件后退出。 |
--fullpaths | 与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项。 |
--gui[+|-] | 启用或禁用 Windows 窗体事件循环。 默认值处于启用状态。 |
--help -? |
用于显示命令行语法和每个选项的简要说明。 |
--lib:<folder-list> -I:<文件夹列表> |
与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项。 |
--load:<filename> | 在启动时编译给定的源代码,并将已编译的 F# 构造加载到会话中。 |
--mlcompatibility | 与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项。 |
--noframework | 与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项 |
--nologo | 与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项。 |
--nowarn:<warning-list> | 与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项。 |
--optimize[+|-] | 与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项。 |
--preferreduilang:<lang> | 指定首选输出语言文化名称(例如,es-ES,ja-JP)。 |
--quiet | 抑制 F# 交互窗口向 stdout 流的输出。 |
--quotations-debug | 指定应为派生自 F# 引用文本和反射定义的表达式发出的额外调试信息。 调试信息将添加到 F# 表达式树节点的自定义属性中。 请参阅代码引用和 Expr.CustomAttributes。 |
--readline[+|-] | 启用或禁用交互模式下的选项卡补全。 |
--reference:<filename> -r:<文件名> |
与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项。 |
--tailcalls[+|-] | 启用或禁用尾 IL 指令,这将导致对尾递归函数重复使用堆栈帧。 此选项默认处于启用状态。 |
--targetprofile:<string> | 指定此程序集的目标框架特性。 有效值为 mscorlib 、netcore 或 netstandard 。 默认值为 mscorlib 。 |
--use:<filename> | 告知解释器在启动时使用给定的文件作为初始输入。 |
--utf8output | 与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项。 |
--warn:<警告级别> | 与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项。 |
--warnaserror[+|-] | 与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项。 |
--warnaserror[+|-]:<int-list> | 与 fsc.exe 编译器选项相同。 有关详细信息,请参阅 编译器选项。 |
F# 交互式结构化打印
F# Interactive (dotnet fsi
) 使用扩展版本的 结构化纯文本格式 来报告值。
支持
%A
纯文本格式的所有功能,有些功能也可自定义。如果输出控制台支持颜色,则打印将着色。
除非您显式评估该字符串,否则显示的字符串长度会受到限制。
可通过
fsi
对象获取一组用户定义设置。
自定义报告值的纯文本打印的可用设置包括:
open System.Globalization
fsi.FormatProvider <- CultureInfo("de-DE") // control the default culture for primitives
fsi.PrintWidth <- 120 // Control the width used for structured printing
fsi.PrintDepth <- 10 // Control the maximum depth of nested printing
fsi.PrintLength <- 10 // Control the length of lists and arrays
fsi.PrintSize <- 100 // Control the maximum overall object count
fsi.ShowProperties <- false // Control whether properties of .NET objects are shown by default
fsi.ShowIEnumerable <- false // Control whether sequence values are expanded by default
fsi.ShowDeclarationValues <- false // Control whether values are shown for declaration outputs
使用 AddPrinter
和 AddPrintTransformer
进行自定义
可使用 fsi.AddPrinter
和 fsi.AddPrintTransformer
对在 F# 交互窗口输出中打印进行自定义。
第一个函数提供用于替换对象打印的文本。 第二个函数返回要显示的替代对象。 例如,请考虑以下 F# 代码:
open System
fsi.AddPrinter<DateTime>(fun dt -> dt.ToString("s"))
type DateAndLabel =
{ Date: DateTime
Label: string }
let newYearsDay1999 =
{ Date = DateTime(1999, 1, 1)
Label = "New Year" }
如果在 F# Interactive 中执行该示例,它将基于格式设置选项集输出。 在这种情况下,它会影响日期和时间的格式:
type DateAndLabel =
{ Date: DateTime
Label: string }
val newYearsDay1999 : DateAndLabel = { Date = 1999-01-01T00:00:00
Label = "New Year" }
可以使用 fsi.AddPrintTransformer
来提供打印的代理对象。
type MyList(values: int list) =
member _.Values = values
fsi.AddPrintTransformer(fun (x:MyList) -> box x.Values)
let x = MyList([1..10])
此输出:
val x : MyList = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]
如果传递给 fsi.AddPrintTransformer
的转换器函数返回 null
,则忽略打印转换器。
这可用于从类型 obj
开始筛选任何输入值。 例如:
fsi.AddPrintTransformer(fun (x:obj) ->
match x with
| :? string as s when s = "beep" -> box ["quack"; "quack"; "quack"]
| _ -> null)
let y = "beep"
此输出:
val y : string = ["quack"; "quack"; "quack"]
相关主题
标题 | 描述 |
---|---|
编译器选项 | 介绍可用于 F# 编译器的命令行选项,fsc.exe。 |