[Haskell-cafe] Re: Exception handling in numeric computations
jwlato at gmail.com
Thu Mar 26 14:01:36 EDT 2009
> Message: 15
> From: Xiao-Yong Jin <xj2106 at columbia.edu>
> John Lato <jwlato at gmail.com> writes:
> So I have another question. Is the following function safe
> and legitimate?
>> safeDiv :: (Exception e, Integral a) =>
>> a -> a -> Either e a
>> safeDiv x y = unsafePerformIO . try . evaluate $ div x y
> I believe it should be okay to use this 'safeDiv'. What do
> you think?
Your question is unclear. Are you asking if this function can be
safely used with current Haskell standards and implementations or are
you asking should the Haskell specification make a guarantee that this
function will do what you want?
I would answer "no" either way, but for different reasons. Common to
both is: Don't use unsafe* functions unless you can prove that your
usage is safe. That is proof as in mathematical usage; it must be
rigorous and complete.
More information about the Haskell-Cafe