Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shadowing in version 4.5

Tags:

f#

shadowing

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"
like image 391
Sergei Avatar asked Jul 22 '19 07:07

Sergei


People also ask

What is method shadowing in Java?

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.

What is shadowing in VB NET?

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.

What is the difference between shadowing and MyClass?

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.

What is the difference between overriding and shadowing?

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.


1 Answers

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
like image 114
TheQuickBrownFox Avatar answered Sep 27 '22 19:09

TheQuickBrownFox