[Haskell-cafe] Newbie: Is it possible to catch _|_ ?
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 :-)
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).
More information about the Haskell-Cafe