我只是試圖去通過維基教科書,學習一些F#:https://en.wikibooks.org/wiki/F_Sharp_Programming/F#主VS main()的語法
考慮從下面的例子: https://en.wikibooks.org/wiki/F_Sharp_Programming/Mutable_Data
open System
let withSideEffects x =
x := "assigned from withSideEffects function"
let refTest() =
let msg = ref "hello"
printfn "%s" !msg
let setMsg() =
msg := "world"
setMsg()
printfn "%s" !msg
withSideEffects msg
printfn "%s" !msg
let main() =
refTest()
Console.ReadKey(true) |> ignore
main()
我意識到,他們把( )在每個有副作用的功能之後。去除大括號編譯平衡良好,並將類型從單位 - >單位更改爲單位。
問題:
- 這是某種形式的F#程序員之間的沉默aggrement的?
- 2種語法之一有沒有好處?
另請參見:爲什麼F#函數在被調用之前評估?(https://stackoverflow.com/questions/32855383/why-do-f-functions-evaluate-before-they-arecall) – ildjarn