2

I am using F# often in a interactive way. I type statements in a script file in Visual Studio and press Alt + Enter to execute them in F# Interactive. Very often I see the warning that I am ignoring the result of an expression. Of course I'm not, because I evaluate everything interactively.

Is there an option to turn this warning off?

Example:

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

1 Answers1

2

F# Interactive has various options including one to suppress compiler warning messages:

--nowarn:<warning-list>

For more details see:

/nowarn (C# Compiler Options)

As an example:

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

F# Interactive returns

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

For

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

F# Interactive returns

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

Notice the warning is now gone.

To use nowarn you need to know the warning number which are like:

warning FS0025

It is the last digits of the warning code that you want to use with #nowarn and do not forget the quotes around the number.

So for FS0025 it is #nowarn "25"

Guy Coder
  • 24,501
  • 8
  • 71
  • 136