On Mon, 2009-03-23 at 08:11 -0400, Xiao-Yong Jin wrote: > Hi, > > I just feel it is not comfortable to deal with exceptions > only within IO monad, so I defined > > > tryArith :: a -> Either ArithException a > > tryArith = unsafePerformIO . try . evaluate
You must not do this. It breaks the semantics of the language. Other people have given practical reasons why you should not but a theoretical reason is that you've defined a non-continuous function. That is impossible in the normal semantics of pure functional languages. So you're breaking a promise which we rely on. It is not "safe". It's almost as bad as a function isBottom, which is the canonical non-continuous function. It's defined by: isBottom _|_ = True isBottom _ = False Of course your tryArith only tests for certain kinds of _|_ value, but in principle the problem is the same. It is not safe because it distinguishes values that are not supposed to be distinguishable. This invalidates many properties and transformations. Duncan _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
