Indeed Haskell the language doesn't do any IO. Instead, it creates a tuple containing
* a description of the action to execute (e.g. read line from STDIN)
* a function that will take the result of the previous action (e.g. the line) and return the next action to execute (e.g. writeLine)
[readLine, \line -> writeLine(line)]
This main action is just a description, the runtime itself takes it, does the actual IO described in the first part of this tuple, evaluates the second (function) part of the tuple with the result of that IO, receives a new pair of action/function, does the action's IO part, evaluates the new function and so on until it gets a nil (end of the "linked list" so to speak)
You could imagine this as a linked list of actions, where the "link" is actually a pure function you call with the result of execution the first part to get the rest of the list (or nil to terminate). This is still pure because the action itself doesn't do anything. If you return an action from a function, it doesn't actually execute, its just a value to be interpreted.
Does that make a real difference or is it just theoretical "purity"? Yes it does make a difference.
For example, if you create two action values, you haven't actually run anything yet, just created descriptions of actions. You could put them in a list and create an action description that will tell the runtime to run them in parallel, for example using: https://hackage.haskell.org/package/parallel-io-0.3.3/docs/C... ... or in sequence https://hackage.haskell.org/package/base-4.10.0.0/docs/Prelu...
For refactoring, it means that you can still take functions that return actions and substitute them with their values, e.g. if you have
readItems 0 = return []
readItems n = do
x <- readLine
y <- readItems (n - 1)
x :: y
main :: IO
items <- readItems 3
putStrLn "The first item is " ++ (head items)
you could pull (readItems 3) out of main!
read3Items = readItems 3
main :: IO
items <- read3Items
putStrLn ...
and everything is exactly the same, since all you've pulled out is a description of an action. Equational reasoning (you can substitute an equation with its result) still works - which is great for refactoring!