What does exactly make reading from the process memory a pure operation? Suppose I created an array of 100 integers in the global memory and then took the 42th element of this array. It is not a side effect, right? So why is reading the same array of 100 integers from a file a side-effect?
Why is reading from memory not a side-effect but reading from a file is?
functional programming;side effect
If the memory you access can change, then it is indeed a side effect.For example, in Haskell, the function to access a mutable array (IOArray) has typeIx i => IOArray i e -> i -> IO e(slightly simplified for our purposes). While accessing an immutable array has typeIx i => Array i e -> i -> eThe first version returns something of type IO e which means it has I/O side effects. The second version simply returns an element of type e without any side effects.In case of accessing a file, you simply cannot know at compile time whether the file will ever change during a run of the program. Therefore, you have to always treat it as an operation with potential side effects.