Newbie: Is it possible to catch _|_ ?

Another newbie question: Is it possible to catch _|_ - that is, to encounter it, handle it and continue? I'm assuming that you all are going to say no, since I can't figure out any way to do this and retain the functional nature of Haskell.

"Russ Lewis"
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 I haven't seen further, it is by standing in the footprints of giants

Ketil Malde wrote:
"Russ Lewis"
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

Oh. I was figuring that the runtime would detect _|_ whenever evaluation requires that it calculate a given expressoin, and that expression is currently being evaluated...that is, some subset of an expression evaluates to the expression itself. Now that you mention it, I guess there are a lot of other nonterminating conditions....hmmm. Thanks for the prompt response! Russ Lewis Experienced imperative programmer, functional newbie :) Ketil Malde wrote:
"Russ Lewis"
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

"Russ Lewis"
Oh. I was figuring that the runtime would detect _|_ whenever evaluation requires that it calculate a given expressoin, and that expression is currently being evaluated...that is, some subset of an expression evaluates to the expression itself.
You mean like in fibs = 1:1:zipWith (+) fibs (tail fibs) ? :-) Actually, (and more seriously) I suspect this is the kind of loop detection that makes GHC go "Exception: loop" (which you may be able to catch; I don't know the details since I just let my programs crash instead :-) Prelude> let x = x Prelude> x *** Exception: <<loop>> -kzm -- If I haven't seen further, it is by standing in the footprints of giants

Am Dienstag, 6. April 2004 16:23 schrieb Russ Lewis:
Another newbie question: Is it possible to catch _|_ - that is, to encounter it, handle it and continue? I'm assuming that you all are going to say no, since I can't figure out any way to do this and retain the functional nature of Haskell.
If you want to signal errors and later catch them, you probably should use Maybe value instead of value as the return types of your functions in question. Wolfgang
participants (4)
-
Bjorn Bringert
-
Ketil Malde
-
Russ Lewis
-
Wolfgang Jeltsch