Notes (HPFP 29/31): IO

29 IO

is that it inverts the usual perspective of subjective thought happening within an objective world. IO is like looking into the universe from the plane of pure Platonic computation, calculating its physics forward a step in time, and then plucking out the type a you happen to want. It’s a very heady perspective, and small wonder people get hooked on it.

But it’s important to remember that this perspective is a lie. GHC is only simulating the outside-view; the code we run is still very much within the universe and generating causal effects like heating our cpu, increasing our electric bill etc. etc. These effects are usually (but not always) small, which is what makes the simulated outside perspective useful.

The outside perspective preserves purity by modeling (or pretending to model) the whole universe as a pure function. The IO type is that model, it makes GHC safely switch off simulating computation as something that happens outside of time and space. Within IO, GHC respects RealWorld time, and doesn’t mess with our execution order.