Why are there no warnings about unused bindings?

C # warns of unused variables that are compile-time constants:

static void Main(string[] args)
{
    var unused = "hey"; //CS0219 The variable 'unused' is assigned but its value is never used
    Console.WriteLine("Hello World!");
}

But the F # compiler does not do this, even if the editor now takes it:

enter image description here

If it covered not only compile-time constants, but also all let bindings, this would lead to a real error in operation caused by a trivial error, something like

let callApiXyz connectionInfo = async {
    let fullUrl = sprintf "%s..." connectionInfo.Url
    ...
    let! result = httpGet connectionInfo // fail, didn't use the modified url
    // Should have been:
    // let! result = httpGet { connectionInfo with Url = fullUrl }
    ...
}

Is there any reason not to have this (other than "features are not free")? I feel this should be more important in a functionally first language, where expressions tend to have no side effects than in C #.

+5
source share
2 answers

warnon warnon. , warnaserror+ .

- 1182, , F #.

fsc --warnaserror+:1182 --warnon:1182 Program.fs

, . Visual Studio , " " " " .

+5

, Visual Studio fsproj , Tomas:

<PropertyGroup>
    <OtherFlags>$(OtherFlags) --warnon:1182</OtherFlags>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

FSharp.Core.

0

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


All Articles