[Haskell-cafe] Error handling in calculations

Roman Cheplyaka roma at ro-che.info
Wed Mar 19 17:03:51 EDT 2008


* hjgtuyl at chello.nl <hjgtuyl at chello.nl> [2008-03-19 21:47:52+0100]
>
> L.S.,
>
> When playing with exceptions, I noticed the following strangeness:
>   *Main> 1 / 0
>   Infinity
>   *Main> 1 `div` 0
>   *** Exception: divide by zero
>
> This is in GHCi 6.8.2; WinHugs Sep 2006 gives:
>   Main> 1 / 0
>   1.#INF
>   Main> 1 `div` 0
>
>   Program error: divide by zero
>
> Is this difference between fractional and integral calculation  
> intentional? It makes error handling more difficult.

I think it's because in the first case you have floating-point overflow
(which can happen not just in case of division by 0 and means some
very-large number -- remember, you cannot distinguish 0 and 0.00..001)
and in the second case it's just division by zero -- meaningless
operation.

-- 
Roman I. Cheplyaka :: http://ro-che.info/
...being in love is totally punk rock...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 307 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080319/c40e3425/attachment.bin


More information about the Haskell-Cafe mailing list