Is this a F # Builder bug or is it my misunderstanding?

When I tried console programming, I got an unexpected result.

open System

let printSomeMessage =        
    printfn "Is this the F# BUG?"    

[<EntryPoint>]
let main args =    
    if args.Length = 2 then
        printSomeMessage
    else        
        printfn "Args.Length is not two."
    0

The printSomeMessage function has been included in the .cctor () function. Here is the result of IL DASM.

.method private specialname rtspecialname static 
        void  .cctor() cil managed
{
  // Code size       24 (0x18)
  .maxstack  4
  IL_0000:  nop
  IL_0001:  ldstr      "Is this the F# BUG\?"
  IL_0006:  newobj     instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5<class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [mscorlib]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit>::.ctor(string)
  IL_000b:  call       !!0 [FSharp.Core]Microsoft.FSharp.Core.ExtraTopLevelOperators::PrintFormatLine<class [FSharp.Core]Microsoft.FSharp.Core.Unit>(class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4<!!0,class [mscorlib]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit>)
  IL_0010:  dup
  IL_0011:  stsfld     class [FSharp.Core]Microsoft.FSharp.Core.Unit '<StartupCode$FSharpBugTest>'.$Program::printSomeMessage@3
  IL_0016:  pop
  IL_0017:  ret
} // end of method $Program::.cctor

So, the result of its execution is as follows.

Is this the F# BUG?
Args.Length is not two.

Is there any lack of grammar or characteristics of F #? Or F # builders BUG?

+5
source share
1 answer

No, this is a mistake in the code. You need to add parentheses after "printSomeMessage", otherwise printSomeMessage is a simple value, not a function.

open System

let printSomeMessage() =        
    printfn "Is this the F# BUG?"    

[<EntryPoint>]
let main args =    
    if args.Length = 2 then
        printSomeMessage()
    else        
        printfn "Args.Length is not two."
    0

, , , . , , string, integer . , , . .. :

let x = 1
let y = "my string"
+10

All Articles