How does fsi.ShowDeclarationValues work?

2020-04-24 17:14发布

According to the MSDN documentaion:

When set to false, disables the display of declaration values in the output of the interactive session.

However, the following sample interactive session seems to contradict that summary.

> let x = 42;;

val x : int = 42

> fsi.ShowDeclarationValues <- false;;

val it : unit = ()

> let y = 42;;

val y : int

I was not expecting the last line above.

Have I misunderstood something? Can anyone confirm if this is a bug?

Thanks.

2条回答
一夜七次
2楼-- · 2020-04-24 17:30

Looks to me that it didn't show the value in the last line, only the name and type of the binding.

查看更多
\"骚年 ilove
3楼-- · 2020-04-24 17:50

Daniel is correct - this disables just printing of the values and not the declarations themselves.

One situation where this is useful is when you define some custom printer for a value that creates a new window as a side-effect (e.g. a value that represents a chart or something you want to display).

For example, you could write this:

// Display all evaluated strings in a message box
fsi.ShowDeclarationValues <- false
fsi.AddPrinter(fun (s:string) -> 
  System.Windows.Forms.MessageBox.Show(s) |> ignore; "")

let a = "foo" // Evaluating this line doesn't show message box
let b = "bar" // (dtto)
a + b         // .. but evaluating this line shows the message box!
查看更多
登录 后发表回答