I started to study F# language. I am using VS Community 2017. F# 4.5
I have a question about shadowing. Looks like it doesn't work for me. When I use the same name bindings it tells "Duplicate definition of value 'x'". What is wrong with the code?
let x = "one"
let x = "second"
let x = "third"
Shadowing (method hiding) A method or function of the base class is available to the child (derived) class without the use of the "overriding" keyword. The compiler hides the function or method of the base class. This concept is known as shadowing or method hiding.
Shadowing in Visual Basic. When two programming elements share the same name, one of them can hide, or shadow, the other one. In such a situation, the shadowed element is not available for reference; instead, when your code uses the element name, the Visual Basic compiler resolves it to the shadowing element.
However, the MyClass keyword bypasses the shadowing and accesses the member variable. For an example of shadowing through scope, see How to: Hide a Variable with the Same Name as Your Variable. If a derived class redefines a programming element inherited from a base class, the redefining element shadows the original element.
In shadowing, the signature of an element could be different. In overriding, the signature of the element must be the same. In shadowing, the base class cannot access the newly created child (derived) class method.
You can't shadow values at the module level.
You can shadow values inside some other scope like a function:
let f () =
let x = "one"
let x = "second"
let x = "third"
x
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With