
I'm looking on the Haskell 98 Report, and the definition of (==) for values of type Array a b looks wrong to me. Here is the definition given: a == a' = (assocs a == assocs a') But this fails to account for the array length in each dimension; hence, if x is a 0 x 2 array, y is a 2 x 0, and z is a 0 x 0 array, then x == y x == z, and y == z are all True, even though bounds x != bounds y, bounds x != bounds z, and bounds y != bounds z. This violates the most fundamental property of equality: that if a == b, then you can substitute a for b in an expression without changing the value of the expression. I can't possibly be the first person to have noticed this. So why is equality for Arrays defined this way?

On Mon, May 26, 2014 at 5:12 PM, Kevin Van Horn
I'm looking on the Haskell 98 Report, and the definition of (==) for values of type Array a b looks wrong to me. Here is the definition given:
a == a' = (assocs a == assocs a')
But this fails to account for the array length in each dimension; hence, if
Have you tested this? assocs produces a list whose length depends on the array bounds; (==) on lists accounts for the length. What's left is the possibility of bounds mismatches, but in that case the index elements of the list of pairs produced by assocs will not match and they will compare unequal. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

The arrays he gave as an example had all At least one dimension equal to 0.
So assocs would produce an empty list as far as I remember, so the three
arrays would be considered to be equal indeed. It's a pity I can't check
that right now, I'm on mobile...
Am 26.05.2014 23:37 schrieb "Brandon Allbery"
On Mon, May 26, 2014 at 5:12 PM, Kevin Van Horn
wrote: I'm looking on the Haskell 98 Report, and the definition of (==) for values of type Array a b looks wrong to me. Here is the definition given:
a == a' = (assocs a == assocs a')
But this fails to account for the array length in each dimension; hence, if
Have you tested this? assocs produces a list whose length depends on the array bounds; (==) on lists accounts for the length. What's left is the possibility of bounds mismatches, but in that case the index elements of the list of pairs produced by assocs will not match and they will compare unequal.
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Mon, May 26, 2014 at 7:01 PM, Norbert Melzer
The arrays he gave as an example had all At least one dimension equal to 0. So assocs would produce an empty list as far as I remember, so the three arrays would be considered to be equal indeed. It's a pity I can't check that right now, I'm on mobile...
Then I would indeed expect them to be trivially equal in H'98. I think if you're looking for anything more precise, you need to switch to something that can't be represented in H'98 or even H'2010, namely arrays with the bounds in the type. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
participants (3)
-
Brandon Allbery
-
Kevin Van Horn
-
Norbert Melzer