开发者

Making printfn/IO pure in F#

开发者 https://www.devze.com 2023-03-17 05:42 出处:网络
There doesn\'t开发者_Python百科 seem to be much online on making sure functions remains pure in F#.

There doesn't开发者_Python百科 seem to be much online on making sure functions remains pure in F#.

To create an example, is there any way to make printfn/IO pure in F#?


you can google for F# implementations of Haskell's IO monad. Here's a nice example.


Printing to the Console is per definition something that changes state (console state) and do have side-effects (like deleting some of the console buffer).

If you are using somekind of CodeContracts or the like you should consider writing out the function result somewhere else, or using an assertion (Contract.Assume or Contract.Assert(this is used for static assertions)) for easier confirmation that you code works.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号