H98: Ix class

Matt Harden matth@mindspring.com
Mon, 10 Sep 2001 21:18:40 -0500


Simon Peyton-Jones wrote:
> 
> Folks, (esp Matt, Jan-Willem)
> 
> Back from ICFP, I have resumed my increasingly small circles around the
> Revised Haskell 98 Report.
> 
> In an earlier message (which I enclose for your convenience) I proposed
> to:
>         a) Remove Ord from Ix's superclasses
>         b) Add rangeSize to Ix's methods (with a suitable default
> method)
> 
> As we implemented these changes we discovered that change (a) actually
> breaks existing programs.  Of course it does: now you have to add Ord to
> the signature of any function that compares indices.

Only if such code already has a type signature attached.  People should
just trust in type inference. (;

> This really does
> happen (for example, it happens even in the code for the Array library
> in the Report).

I mentioned this in my original note about this issue.  To quote myself:

>> One change would have to be made in the Array module if Ord is removed
>> from Ix:
>>         instance  (Ix a, Eq b)  => Eq (Array a b)  where
>>             a == a'             =  assocs a == assocs a'
>>         instance  (Ix a, Ord b) => Ord (Array a b)  where
>>             a <=  a'            =  assocs a <=  assocs a'
>> 
>> would become:
>>         instance  (Ix a, Eq a, Eq b)   => Eq (Array a b)  where
>>             a == a'             =  assocs a == assocs a'
>>         instance  (Ix a, Ord a, Ord b) => Ord (Array a b)  where
>>             a <=  a'            =  assocs a <=  assocs a'

> 
> I should have realised this before, but
> 
>                 I therefore withdraw proposal (a).
> 
> It now looks like a perhaps-desirable, but definitely un-forced change,
> and that goes beyond my remit.

That's OK.  I personally don't think it's likely to break anyone's code
outside the Array and Ix modules themselves, but I certainly understand
(and agree with) the desire to minimize changes to H98.  I just didn't
like the idea of having to create an arbitrary Ord instance for Ix types
where there might not be a "natural" comparison.  Especially when the
only reason for it is to allow Arrays to be compared.

> However (b) doesn't break anything, I think, so I propose to let it
> stand.
> (The two are independent I think.)

Agreed; they are independent.  (b) was much more important to me,
anyway.

> Does anyone want to argue that having Ord as a superclass of Ix is So
> Bad
> that it Absolutely Must Be Removed?

I'll pass.

Matt