简体   繁体   中英

Making printfn/IO pure in F#

There doesn't 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 'sa 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM