在下面的代码中,为什么函数printStatement
被调用?
module Tests
let printStatement =
printfn "%s" "statement"
let functionCallingPrintStatement =
printStatement
let functionNotCallingPrintStatement =
printfn "%s" "This is a test"
如果我在主程序中调用functionNotCallingPrintStatement
?
open Tests
[<EntryPoint>]
let main argv =
functionNotCallingPrintStatement
0
这是输出:
声明
这是一个测试
如果我将函数functionNotCallingPrintStatement
更改为:
let functionNotCallingPrintStatement =
()
第一个陈述被压制。
答案 0 :(得分:5)
它们不是函数,它们是unit
val functionNotCallingPrintStatement : unit = ()
要使它们成为unit -> unit
个函数,请添加括号
let functionNotCallingPrintStatement () =
printfn "%s" "This is a test"
val functionNotCallingPrintStatement : unit -> unit