On 25 May 2004 14:22, Malcolm Wallace wrote:
> Simon Peyton Jones <[EMAIL PROTECTED]> writes:
>
>> Remove spaces around the "%" when showing ratios.
>>
>> This is not absolutely strictly according to the H98 report,
>> but it was suggested by Doug McIlroy
>>
>> According to the standard prelude, a list of Ratios prints like
>> this: [1 % 1,1 % 2,1 % 3,1 % 4], which strongly suggests the
>> grouping [1 % (1,1) % (2,1) % (3,1) % 4].
>>
>> Even standing alone outside of lists, the style is at odds with
>> mathematical custom. When did you last see 1/2 written as 1 /
>> 2?
>
> I seem to remember that the rationale for spaces around the % operator
> was to avoid lexing problems with non-canonically represented negative
> Ratios, e.g. 2 % -3. If written as 2%-3, the maximal munch rule
> gives you 2 %- 3, which is not a Ratio. However, perhaps you have
> some other scheme for 'show'ing negatives, e.g. with parentheses?
> 2%(-3)
I seem to remember that issue too, but now that I look at it I can't see
how you would get a Ratio of that form. The definition of % is:
x % y = reduce (x * signum y) (abs y)
So the second argument to reduce is never negative.
Furthermore, even if you manage to construct one, the Show instance for
Ratio puts the parentheses in:
Prelude Ratio> :m +GHC.Real
Prelude Ratio GHC.Real> 1:%(-2)
1 % (-2)
This looks to be what the H98 report says too.
Cheers,
Simon
Cheers,
Simon
_______________________________________________
Cvs-libraries mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/cvs-libraries