F# - Function with no arguments?

偶尔善良 提交于 2019-12-01 02:04:13
sepp2k

The usual idiom is to define the function to take one argument of type Unit (let functionName () = 42). It will then be called as functionName (). (The unit type has only one value, which is ().)

I think what you want is lazy.

let resource = 
    lazy(
        // expensive value init here
    )

Then later when you need to read the value...

resource.Value

If you never call the Value property, the code inside the lazy block never gets run, but if you do call it, that code will be run no more than once.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!