aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Array
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2025-02-18 10:38:30 +0100
committerTom Smeding <tom@tomsmeding.com>2025-02-18 10:38:30 +0100
commitd5402b39f31f4cf56a8f583f1d6ceaf7a8aa5acf (patch)
tree4cdf136ba3a79bb01b04300d0efc8e264ed0b487 /src/Data/Array
parent53e1886fc41f0691dff03f6ff0a88e58f042fa30 (diff)
All arrays are Eq and Ord (they compare shape first, then values)HEADmaster
This comparison policy is lifted straight from orthotope (and indeed the instances are all just auto-derived).
Diffstat (limited to 'src/Data/Array')
-rw-r--r--src/Data/Array/Mixed/XArray.hs5
-rw-r--r--src/Data/Array/Nested/Internal/Mixed.hs6
2 files changed, 7 insertions, 4 deletions
diff --git a/src/Data/Array/Mixed/XArray.hs b/src/Data/Array/Mixed/XArray.hs
index b564e14..71bdc1f 100644
--- a/src/Data/Array/Mixed/XArray.hs
+++ b/src/Data/Array/Mixed/XArray.hs
@@ -38,10 +38,7 @@ import Data.Array.Mixed.Types
type XArray :: [Maybe Nat] -> Type -> Type
newtype XArray sh a = XArray (S.Array (Rank sh) a)
- deriving (Show, Eq, Generic)
-
--- | Only on scalars, because lexicographical ordering is strange on multi-dimensional arrays.
-deriving instance (Ord a, Storable a) => Ord (XArray sh a)
+ deriving (Show, Eq, Ord, Generic)
instance NFData (XArray sh a)
diff --git a/src/Data/Array/Nested/Internal/Mixed.hs b/src/Data/Array/Nested/Internal/Mixed.hs
index 5417a1c..d8b7912 100644
--- a/src/Data/Array/Nested/Internal/Mixed.hs
+++ b/src/Data/Array/Nested/Internal/Mixed.hs
@@ -155,8 +155,14 @@ newtype instance Mixed sh () = M_Nil (Mixed sh (Primitive ())) deriving (Eq, Ord
data instance Mixed sh (a, b) = M_Tup2 !(Mixed sh a) !(Mixed sh b) deriving (Generic)
-- etc., larger tuples (perhaps use generics to allow arbitrary product types)
+deriving instance (Eq (Mixed sh a), Eq (Mixed sh b)) => Eq (Mixed sh (a, b))
+deriving instance (Ord (Mixed sh a), Ord (Mixed sh b)) => Ord (Mixed sh (a, b))
+
data instance Mixed sh1 (Mixed sh2 a) = M_Nest !(IShX sh1) !(Mixed (sh1 ++ sh2) a) deriving (Generic)
+deriving instance Eq (Mixed (sh1 ++ sh2) a) => Eq (Mixed sh1 (Mixed sh2 a))
+deriving instance Ord (Mixed (sh1 ++ sh2) a) => Ord (Mixed sh1 (Mixed sh2 a))
+
-- | Internal helper data family mirroring 'Mixed' that consists of mutable
-- vectors instead of 'XArray's.