News for hackers. Stuff that matters.
Re:Asynchronous Exceptions in Practice by rkrzr on Tuesday January 24, 2017 @11:06AM (#13472442)
"You can throw an exception to another thread, at any time;" "The other thread will receive the exception immediately, whatever it is doing."

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.

Re:Asynchronous Exceptions in Practice by jwlato on Tuesday January 24, 2017 @02:18PM (#13474542)
I surely don't know as much as simonmar about this, but I think this is a rhetorical shortcut. My understanding is that when a Haskell thread receiving the exception needs to allocate on the heap, the executing context will instead raise the exception.

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.

Re:Asynchronous Exceptions in Practice by runeks on Tuesday January 24, 2017 @11:28AM (#13472734)
> And how do you need to look at this for it not to be a side-effect?

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).

Re:Asynchronous Exceptions in Practice by marcosdumay on Tuesday January 24, 2017 @11:11AM (#13472509)
It is not a side-effect because it is part of the execution model.

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.