定义F#函数但不调用它,函数似乎仍然被调用

Las*_*all -2 f#

在下面的代码中,为什么printStatement调用该函数?

module Tests

let printStatement =
    printfn "%s" "statement"

let functionCallingPrintStatement =
    printStatement

let functionNotCallingPrintStatement =
    printfn "%s" "This is a test"
Run Code Online (Sandbox Code Playgroud)

如果我打电话给functionNotCallingPrintStatement我的主程序?

open Tests

[<EntryPoint>]
let main argv =
    functionNotCallingPrintStatement     
    0 
Run Code Online (Sandbox Code Playgroud)

这是输出:

声明

这是一个测试

如果我将功能更改functionNotCallingPrintStatement为:

let functionNotCallingPrintStatement =
    ()
Run Code Online (Sandbox Code Playgroud)

第一个陈述被压制.

Jak*_*rtz 5

它们不是函数,它们是类型的值 unit

val functionNotCallingPrintStatement : unit = ()
Run Code Online (Sandbox Code Playgroud)

要使它们unit -> unit起作用,请添加括号

let functionNotCallingPrintStatement () =
    printfn "%s" "This is a test"

val functionNotCallingPrintStatement : unit -> unit
Run Code Online (Sandbox Code Playgroud)