aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Array
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-12-17 22:30:30 +0100
committerTom Smeding <tom@tomsmeding.com>2024-12-17 22:30:30 +0100
commitd39ea901a67d17b0f33cdb4f76985e37208a9447 (patch)
tree46fe50a8e4ca1db1e8a04fc5b17c4307170b0ca9 /src/Data/Array
parent1b8403a66572c3ed85580ec6745130ad1627042e (diff)
Uniform Show instance for Mixed
The previous code was needlessly complicated.
Diffstat (limited to 'src/Data/Array')
-rw-r--r--src/Data/Array/Nested/Internal/Mixed.hs21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/Data/Array/Nested/Internal/Mixed.hs b/src/Data/Array/Nested/Internal/Mixed.hs
index 8813ab3..b155da5 100644
--- a/src/Data/Array/Nested/Internal/Mixed.hs
+++ b/src/Data/Array/Nested/Internal/Mixed.hs
@@ -139,7 +139,6 @@ data family Mixed sh a
data instance Mixed sh (Primitive a) = M_Primitive !(IShX sh) !(XArray sh a)
deriving (Eq, Generic)
- deriving (Show) via (ShowViaToListLinear sh (Primitive a))
-- | Only on scalars, because lexicographical ordering is strange on multi-dimensional arrays.
deriving instance (Ord a, Storable a) => Ord (Mixed sh (Primitive a))
@@ -147,14 +146,14 @@ deriving instance (Ord a, Storable a) => Ord (Mixed sh (Primitive a))
instance NFData a => NFData (Mixed sh (Primitive a))
-- [PRIMITIVE ELEMENT TYPES LIST]
-newtype instance Mixed sh Bool = M_Bool (Mixed sh (Primitive Bool)) deriving (Eq, Generic) deriving (Show) via (ShowViaPrimitive sh Bool)
-newtype instance Mixed sh Int = M_Int (Mixed sh (Primitive Int)) deriving (Eq, Generic) deriving (Show) via (ShowViaPrimitive sh Int)
-newtype instance Mixed sh Int64 = M_Int64 (Mixed sh (Primitive Int64)) deriving (Eq, Generic) deriving (Show) via (ShowViaPrimitive sh Int64)
-newtype instance Mixed sh Int32 = M_Int32 (Mixed sh (Primitive Int32)) deriving (Eq, Generic) deriving (Show) via (ShowViaPrimitive sh Int32)
-newtype instance Mixed sh CInt = M_CInt (Mixed sh (Primitive CInt)) deriving (Eq, Generic) deriving (Show) via (ShowViaPrimitive sh CInt)
-newtype instance Mixed sh Float = M_Float (Mixed sh (Primitive Float)) deriving (Eq, Generic) deriving (Show) via (ShowViaPrimitive sh Float)
-newtype instance Mixed sh Double = M_Double (Mixed sh (Primitive Double)) deriving (Eq, Generic) deriving (Show) via (ShowViaPrimitive sh Double)
-newtype instance Mixed sh () = M_Nil (Mixed sh (Primitive ())) deriving (Eq, Generic) deriving (Show) via (ShowViaPrimitive sh ()) -- no content, orthotope optimises this (via Vector)
+newtype instance Mixed sh Bool = M_Bool (Mixed sh (Primitive Bool)) deriving (Eq, Generic)
+newtype instance Mixed sh Int = M_Int (Mixed sh (Primitive Int)) deriving (Eq, Generic)
+newtype instance Mixed sh Int64 = M_Int64 (Mixed sh (Primitive Int64)) deriving (Eq, Generic)
+newtype instance Mixed sh Int32 = M_Int32 (Mixed sh (Primitive Int32)) deriving (Eq, Generic)
+newtype instance Mixed sh CInt = M_CInt (Mixed sh (Primitive CInt)) deriving (Eq, Generic)
+newtype instance Mixed sh Float = M_Float (Mixed sh (Primitive Float)) deriving (Eq, Generic)
+newtype instance Mixed sh Double = M_Double (Mixed sh (Primitive Double)) deriving (Eq, Generic)
+newtype instance Mixed sh () = M_Nil (Mixed sh (Primitive ())) deriving (Eq, Generic) -- no content, orthotope optimises this (via Vector)
-- etc.
-- [PRIMITIVE ELEMENT TYPES LIST]
@@ -168,12 +167,10 @@ 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 via (ShowViaToListLinear sh (a, b)) instance (Show a, Elt a, Show b, Elt b) => Show (Mixed sh (a, b))
instance (NFData (Mixed sh a), NFData (Mixed sh b)) => NFData (Mixed sh (a, b))
-- etc., larger tuples (perhaps use generics to allow arbitrary product types)
data instance Mixed sh1 (Mixed sh2 a) = M_Nest !(IShX sh1) !(Mixed (sh1 ++ sh2) a) deriving (Generic)
-deriving via (ShowViaToListLinear sh1 (Mixed sh2 a)) instance (Show (Mixed sh2 a), Elt a) => Show (Mixed sh1 (Mixed sh2 a))
instance NFData (Mixed (sh1 ++ sh2) a) => NFData (Mixed sh1 (Mixed sh2 a))
@@ -219,6 +216,8 @@ instance (Show a, Storable a) => Show (ShowViaPrimitive sh a) where
showString "mfromListLinear " . shows (shxToList sh) . showString " "
. shows (coerce @[Primitive a] @[a] (mtoListLinear parr))
+deriving via (ShowViaToListLinear sh a) instance (Show a, Elt a) => Show (Mixed sh a)
+
mliftNumElt1 :: (PrimElt a, PrimElt b)
=> (SNat (Rank sh) -> S.Array (Rank sh) a -> S.Array (Rank sh) b)