From cf42449abd68cc5c5648a1321df21f3c481e8b87 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 7 Jun 2024 21:46:05 +0200 Subject: Generalise Ord instances to full lexicographical order --- src/Data/Array/Mixed/XArray.hs | 2 +- src/Data/Array/Nested/Internal/Mixed.hs | 16 ++++++++-------- src/Data/Array/Nested/Internal/Ranked.hs | 2 +- src/Data/Array/Nested/Internal/Shaped.hs | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Data/Array/Mixed/XArray.hs b/src/Data/Array/Mixed/XArray.hs index cc0a6a5..e93ffca 100644 --- a/src/Data/Array/Mixed/XArray.hs +++ b/src/Data/Array/Mixed/XArray.hs @@ -39,7 +39,7 @@ 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 '[] a) +deriving instance (Ord a, Storable a) => Ord (XArray sh a) instance NFData a => NFData (XArray sh a) diff --git a/src/Data/Array/Nested/Internal/Mixed.hs b/src/Data/Array/Nested/Internal/Mixed.hs index 09fb82b..1776687 100644 --- a/src/Data/Array/Nested/Internal/Mixed.hs +++ b/src/Data/Array/Nested/Internal/Mixed.hs @@ -128,7 +128,7 @@ data instance Mixed sh (Primitive a) = M_Primitive !(IShX sh) !(XArray 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 (Mixed '[] (Primitive a)) +deriving instance (Ord a, Storable a) => Ord (Mixed sh (Primitive a)) instance NFData a => NFData (Mixed sh (Primitive a)) @@ -143,13 +143,13 @@ newtype instance Mixed sh () = M_Nil (Mixed sh (Primitive ())) deriving (Show, E -- etc. -- [PRIMITIVE ELEMENT TYPES LIST] -deriving instance Ord (Mixed '[] Int) ; instance NFData (Mixed sh Int) -deriving instance Ord (Mixed '[] Int64) ; instance NFData (Mixed sh Int64) -deriving instance Ord (Mixed '[] Int32) ; instance NFData (Mixed sh Int32) -deriving instance Ord (Mixed '[] CInt) ; instance NFData (Mixed sh CInt) -deriving instance Ord (Mixed '[] Float) ; instance NFData (Mixed sh Float) -deriving instance Ord (Mixed '[] Double) ; instance NFData (Mixed sh Double) -deriving instance Ord (Mixed '[] ()) ; instance NFData (Mixed sh ()) +deriving instance Ord (Mixed sh Int) ; instance NFData (Mixed sh Int) +deriving instance Ord (Mixed sh Int64) ; instance NFData (Mixed sh Int64) +deriving instance Ord (Mixed sh Int32) ; instance NFData (Mixed sh Int32) +deriving instance Ord (Mixed sh CInt) ; instance NFData (Mixed sh CInt) +deriving instance Ord (Mixed sh Float) ; instance NFData (Mixed sh Float) +deriving instance Ord (Mixed sh Double) ; instance NFData (Mixed sh Double) +deriving instance Ord (Mixed sh ()) ; instance NFData (Mixed sh ()) data instance Mixed sh (a, b) = M_Tup2 !(Mixed sh a) !(Mixed sh b) deriving (Generic) deriving instance (Show (Mixed sh a), Show (Mixed sh b)) => Show (Mixed sh (a, b)) diff --git a/src/Data/Array/Nested/Internal/Ranked.hs b/src/Data/Array/Nested/Internal/Ranked.hs index f834d54..ec18899 100644 --- a/src/Data/Array/Nested/Internal/Ranked.hs +++ b/src/Data/Array/Nested/Internal/Ranked.hs @@ -59,7 +59,7 @@ type Ranked :: Nat -> Type -> Type newtype Ranked n a = Ranked (Mixed (Replicate n Nothing) a) deriving instance Show (Mixed (Replicate n Nothing) a) => Show (Ranked n a) deriving instance Eq (Mixed (Replicate n Nothing) a) => Eq (Ranked n a) -deriving instance Ord (Mixed '[] a) => Ord (Ranked 0 a) +deriving instance Ord (Mixed (Replicate n Nothing) a) => Ord (Ranked n a) deriving instance NFData (Mixed (Replicate n Nothing) a) => NFData (Ranked n a) -- just unwrap the newtype and defer to the general instance for nested arrays diff --git a/src/Data/Array/Nested/Internal/Shaped.hs b/src/Data/Array/Nested/Internal/Shaped.hs index c640a44..b4dc80d 100644 --- a/src/Data/Array/Nested/Internal/Shaped.hs +++ b/src/Data/Array/Nested/Internal/Shaped.hs @@ -57,7 +57,7 @@ type Shaped :: [Nat] -> Type -> Type newtype Shaped sh a = Shaped (Mixed (MapJust sh) a) deriving instance Show (Mixed (MapJust sh) a) => Show (Shaped sh a) deriving instance Eq (Mixed (MapJust sh) a) => Eq (Shaped sh a) -deriving instance Ord (Mixed '[] a) => Ord (Shaped '[] a) +deriving instance Ord (Mixed (MapJust sh) a) => Ord (Shaped sh a) deriving instance NFData (Mixed (MapJust sh) a) => NFData (Shaped sh a) -- just unwrap the newtype and defer to the general instance for nested arrays -- cgit v1.2.3-70-g09d2