[Haskell-beginners] Haskell type Array a b

Kevin Van Horn kevin at ksvanhorn.com
Mon May 26 21:12:02 UTC 2014


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?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140526/ff935013/attachment.html>


More information about the Beginners mailing list