Hello, I am learning Haskell and I am at the stage where IO comes into play.
I need help to clearly understand why this IO is used.
One can imagine a getline implementation returning a list which content is [“firt user input”, “second user input”, etc…].
Clearly, the values contained in this list as well as the list length are not known at compile time (lazy evaluation will know as needed). Also, values will change at each program execution.
Nevertheless, such a function would still be a pure function in the scope of one program execution.
The idea of a Haskell program being executed within a fully “pure world” seems thinkable to me. In such a world, external data are all immutable but exist in several “versions”. Each version remaining accessible to the program if needed.
The here above implementation of is an example for data input but the approach can be general.
For example, a data base can be implemented along that approach if each db modification is exposed as a full new db. Within the scope of a program execution, several db states should then remain accessible to the program. This is comparable to string modifications in Haskell but at the level of a db. The implementation may be a challenge regarding optimization but is probably doable.
Thanks in advance for taking the time to share your knowledge,
Silvio.