From d5402b39f31f4cf56a8f583f1d6ceaf7a8aa5acf Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 18 Feb 2025 10:38:30 +0100 Subject: All arrays are Eq and Ord (they compare shape first, then values) This comparison policy is lifted straight from orthotope (and indeed the instances are all just auto-derived). --- src/Data/Array/Mixed/XArray.hs | 5 +---- src/Data/Array/Nested/Internal/Mixed.hs | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src/Data') 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. -- cgit v1.2.3-70-g09d2