2

我经常以交互方式使用 F#。我在 Visual Studio 的脚本文件中键入语句,然后Alt + Enter在 F# Interactive 中按下以执行它们。我经常看到我忽略了表达式结果的警告。我当然不是,因为我以交互方式评估所有内容。

是否有关闭此警告的选项?

例子:

let numbers = "151,160,137,91,90,15"
numbers.ToCharArray() 
|> Array.filter (fun e-> e=',')
|> Array.length
4

1 回答 1

2

F# Interactive 有多种选项,包括一种用于抑制编译器警告消息的选项:

--nowarn:<warning-list>

有关更多详细信息,请参阅:

/nowarn(C# 编译器选项)

举个例子:

match [] with | a::b -> 0

F# Interactive 回归

Script.fsx(9,7): warning FS0025: Incomplete pattern matches on this expression. 
For example, the value '[]' may indicate a case not covered by the pattern(s).

Microsoft.FSharp.Core.MatchFailureException: 
The match cases were incomplete at <StartupCode$FSI_0003>.$FSI_0003.main@() in
   C:\Users\Eric\Documents\Visual Studio2015\Projects\Workspace\Library2\Script.fsx:line 9 
Stopped due to error

为了

#nowarn "25"
match [] with | a::b -> 0

F# Interactive 回归

Microsoft.FSharp.Core.MatchFailureException: 
The match cases were incomplete at <StartupCode$FSI_0004>.$FSI_0004.main@() in 
  C:\Users\Eric\Documents\Visual Studio 2015\Projects\Workspace\Library2\Script.fsx:line 9
Stopped due to error

注意警告现在消失了。

要使用nowarn,您需要知道警告编号,例如:

warning FS0025

这是您要使用的警告代码的最后一位数字,#nowarn不要忘记数字周围的引号。

所以对于 FS0025 它是#nowarn "25"

于 2016-05-11T18:02:28.180 回答