F#忽略丢失忽略

时间:2016-05-11 17:30:12

标签: f# fsi

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

是否可以选择关闭此警告?

示例:

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

1 个答案:

答案 0 :(得分:2)

F#Interactive有各种options,其中一个用于禁止编译器警告消息:

--nowarn:<warning-list>

有关详细信息,请参阅:

/nowarn (C# Compiler Options)

举个例子:

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"