blackholes and exception handling

Sebastian Fischer sebf at informatik.uni-kiel.de
Sat May 1 18:10:23 EDT 2010


Hello,

GHC can spot (some) non-terminating computations and terminate with

     blackhole: <<loop>>

instead of running indefinitely. With exception handling one can  
handle such situations. The following program 'launches missiles':

     import Control.Exception

     main = do handle go_ahead don't_launch_first
               launch_missiles

     don't_launch_first = don't_launch_first

     go_ahead :: SomeException -> IO ()
     go_ahead _ = putStr "go ahead, "

     launch_missiles = putStr "fire!"

The output of this program is

     go ahead, fire!

although,  don't_launch_first  is a non-terminating computation.  
Without black-hole detection this code would never 'launch missiles'.

Is the above output intended?

The idea behind black-hole detection is that one bottom is as good as  
another [1]. Consequently, exception handling may not distinguish  
between non-termination and other errors.

Is the equation

     _|_ `catch` const a  =  a

supposed to hold in general (for every kind of bottom)? Or is it a bug  
in GHC that programmers can handle black-hole errors?

Sebastian

[1] A semantics for imprecise exceptions
      http://portal.acm.org/citation.cfm?id=301637

-- 
Underestimating the novelty of the future is a time-honored tradition.
(D.G.)





More information about the Glasgow-haskell-users mailing list