[Haskell-cafe] Newbie: Is it possible to catch _|_ ?

Bjorn Bringert d00bring at dtek.chalmers.se
Tue Apr 6 18:45:28 EDT 2004

Ketil Malde wrote:
> "Russ Lewis" <spamhole-2001-07-16 at deming-os.org> writes:
>> Another newbie question: Is it possible to catch _|_ - that is, to
>> encounter it, handle it and continue?
> Since _|_ is the value of a non-terminating computation, this requires
> you to solve the halting problem.  GHC does occasionally detect loops,
> but for the general case, don't hold your breath :-)
> -kzm

If all you are interested in is catching calls to error, they can be 
caught like normal exceptions. Here is some code from Network.XmlRpc 
that catches error calls and handles them in an error monad:

type Err m a = ErrorT String m a

-- | Evaluate the argument and catch error call exceptions
errorToErr :: Monad m => a -> Err m a
errorToErr x = let e = unsafePerformIO (tryJust errorCalls (evaluate x))
		   in ErrorT (return e)

Pretty nasty, using evaluate and unsafePerformIO in the same function. 
The essential part is (tryJust errorCalls).

/Bjorn Bringert

More information about the Haskell-Cafe mailing list