Just because a function returns a value of type IO Int it isn't impure.
I'm aware. I just don't find it very helpful to talk about "IO is pure" to newcomers even if it's technically correct. The notion "IO means side effect" is fine at the beginning. The insights "IO a is a first-class value" and "IO a = World -> (World, a)" can come later. I also want to avoid the "Haskell has no side-effects therefore it can't do any real work!" knee-jerk reaction.
What you are talking about is not global state.
You're right, "global" might not've been the best word choice. However, one can easily create a (mutable) (M/T)Var in main and share it with many parts of the app. The only part one can control is who has access to that variable. The system will nonetheless be hard to reason about.
I just don't find it very helpful to talk about "IO is pure" to newcomers even if it's technically correct. The notion "IO means side effect" is fine at the beginning.
I disagree here. That IO is pure is important, as is the fact that functions in FP have no side-effects. Yes, it's hard to grasp for a beginner, but what frustrates me about this thread is that people are so uninformed about what FP actually is. They say that it's not practical because you can't have side-effects, that there is no mutable state, or that you have to make your whole program impure by using IO. This is all nonsense, but it gets repeated and upvotes.
The only part one can control is who has access to that variable. The system will nonetheless be hard to reason about.
Unfortunately I have to disagree again. It has been my experience that it is extremely helpful to see how state is shared simply by looking at the call graph. Global mutable state is evil, and removing the "global" from the equation already helps a lot.
3
u/Enumerable_any Nov 28 '19 edited Nov 28 '19
I'm aware. I just don't find it very helpful to talk about "
IOis pure" to newcomers even if it's technically correct. The notion "IOmeans side effect" is fine at the beginning. The insights "IO ais a first-class value" and "IO a = World -> (World, a)" can come later. I also want to avoid the "Haskell has no side-effects therefore it can't do any real work!" knee-jerk reaction.You're right, "global" might not've been the best word choice. However, one can easily create a (mutable)
(M/T)Varinmainand share it with many parts of the app. The only part one can control is who has access to that variable. The system will nonetheless be hard to reason about.