Is there a way to have warnings for shading values ​​in F # in Visual Studio?

I need to track existing values ​​as described in:

Shadow and Nesting Function
immutable in F #
f # duplicate definition
FSharp for comments about fun and profit

seems to contradict the notion of immutability and type safety, which makes F # so strong. Shading in F # works differently than in C #. It just took me a while to find out that the error in my code was caused by an inadvertent shadowing of the name in the same area. Is there a way to have compiler warnings to obscure values ​​in VS?

I know that in some cases this can be useful. for example, for proven arrhythmias. .

+6
source share
2 answers

The shadow has pros and cons. I also encountered errors due to finger shading efforts. On the plus side, this can help keep the variable space clean, as @JoelMueller pointed out.

Shadow errors are fundamentally different from mutable errors. They have a typical variety. They are much easier to analyze: the historical loss of information comes down to a lexicographic context and an environmental context. That is, with shadow copying, you can always keep track of the value of the binding by turning the mental stack, while mutation variables create what essentially is gotos (go to address).

In practice, shading still eliminates entire classes of errors. You will not encounter any "creepy actions at a distance." Namely, you will not encounter problems with variables captured in closure or variables that change in nested areas compared to the current area.

+3
source

One place I use for shading is to allow an optional default parameter if no value has been provided.

member x.Foo(?myFlag: bool) = let myFlag = defaultArg myFlag false ... 

Also, F # Interactive, the way it was currently implemented, will be largely non-functional if we don't have a shadow.

+4
source

Source: https://habr.com/ru/post/971292/


All Articles