Data.Ratio and exceptions

Simon Marlow marlowsd at gmail.com
Thu Jun 14 12:32:09 CEST 2012


On 14/06/2012 02:27, wren ng thornton wrote:
> On 6/13/12 6:57 AM, Simon Hengel wrote:
>>> I'll go ahead and make this change. Thanks for the suggestion!
>>
>> I agree that ArithException feels more appropriate here. But I make two
>> observations:
>>
>> (1) It replaces specific error messages with less specific ones.
>>
>> The error message will not include the function/operator name
>> anymore, e.g.:
>>
>> ghci> 1 % 0
>> *** Exception: Ratio.%: zero denominator
>>
>> would become:
>>
>> ghci> 1 % 0
>> *** Exception: divide by zero
>
> That's no good. I wonder whether ArithExceptions should be given their
> code location a la assertion failures[1]. Probably all the built-in
> exception types should do so.
>
>
> [1] http://www.haskell.org/ghc/docs/7.4.1/html/users_guide/assertions.html

But that wouldn't help - you'd just get a code location somewhere deep 
in the base package every time.

So we could make a separate RatioZeroDenominator exception, and add that 
to ArithException.  That would mean no loss of information relative to 
the current state of affairs.

Cheers,
	Simon






More information about the Libraries mailing list