Does anybody know how this is implemented in the runtime system? How does one thread communicate with another thread? And how do you need to look at this for it not to be a side-effect?
Any insight is much appreciated.
Does anybody know how this is implemented in the runtime system? How does one thread communicate with another thread? And how do you need to look at this for it not to be a side-effect?
Any insight is much appreciated.
As for why it's not a side effect, in Haskell all exceptions are considered to be bottom, the value that inhabits every type. Thus an exception can be raised anywhere and have any type. They can only be handled in IO though.
I would look at it like this: while a function can be pure (no side effects), the thread in which it executes need not be a pure construct. It's a property of the runtime system, which, essentially, schedules pure functions to run inside green threads, to which exceptions can be thrown (which will terminate the execution of the pure function).
In other words, it's one of the things you don't care about when writing a pure program, like how many times it runs, how many threads are running it, on what order it executes, etc.
It does leak, but only on the IO monad.