
Sterling Clover wrote:
This is perhaps a silly idea, but perhaps useful -- there should be a version of unsafePerformIO that always does the "right" thing with regards to exceptions. From that, the other unamb primitives can perhaps be built more obviously? Additionally, this implementation would be potentially useful to libraries beyond unamb.
You mean something like this? -- | A version of 'unsafePerformIO' that assures that the resulting -- (pure) computation can be restarted if it is killed by an -- asynchronous exception. Note that as a result, the IO action -- may be performed more than once. exceptionSafeUnsafePerformIO act = unsafePerformIO $ retry act where retry act = unblock act `catch` \SomeException e -> do myid <- myThreadId throwTo myid e retry act That could be useful indeed. Btw, in an ideal world we'd distinguish between asynchronous and synchronous exceptions here, and rethrow them appropriately. Sadly, there's currently no way to distinguish them. See http://hackage.haskell.org/trac/ghc/ticket/2558 regards, Bertram