Reputation: 1416
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#?
Upvotes: 1
Views: 1009
Reputation: 25844
you can google for F# implementations of Haskell's IO monad. Here's a nice example.
Upvotes: 8
Reputation: 4289
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.
Upvotes: 0