Skip to content

Eq instance for Array is surprising

Summary

In general, two Arrays are considered == if they have the same bounds and the same elements in each position. However, if the arrays are both empty, then they are considered equal even if they have different bounds. Moreover, this means that bounds does not respect ==.

Steps to reproduce

Data.Array> listArray (1,2) [1,2] == listArray (2,3) [1,2]
False
Data.Array> listArray (1,0) [] == listArray (2,1) []
True
Data.Array> bounds (listArray (1,0) []) == bounds (listArray (2,1) [])
False

Expected behavior

I would expect all of the above to produce False.

Environment

  • GHC version used: 8.10.1

Optional:

  • Operating System:
  • System Architecture:
Edited by David Feuer
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information