开发者

Making printfn/IO 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜