From 8db33035826609bf48e15a82742981a58a0b5982 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sat, 26 Apr 2025 10:27:39 +0200 Subject: Refactor the clever replicate-aware Show instances --- src/Data/Array/Nested/Internal/Ranked.hs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'src/Data/Array/Nested/Internal/Ranked.hs') diff --git a/src/Data/Array/Nested/Internal/Ranked.hs b/src/Data/Array/Nested/Internal/Ranked.hs index cb8aae0..2aba1bc 100644 --- a/src/Data/Array/Nested/Internal/Ranked.hs +++ b/src/Data/Array/Nested/Internal/Ranked.hs @@ -65,17 +65,9 @@ deriving instance Eq (Mixed (Replicate n Nothing) a) => Eq (Ranked n a) deriving instance Ord (Mixed (Replicate n Nothing) a) => Ord (Ranked n a) instance (Show a, Elt a) => Show (Ranked n a) where - showsPrec d arr@(Ranked marr) = showParen (d > 10) $ - let defaultResult = - showString "rfromListLinear " . shows (toList (rshape arr)) . showString " " - . shows (rtoListLinear arr) - in if stridesAreZero (shxLength $ mshape marr) (mstrideTree marr) - then case rtoListLinear arr of - [] -> defaultResult - [_] -> defaultResult - hd : _ -> showString "rreplicate " . shows (toList (rshape arr)) . showString " " - . showsPrec 11 hd - else defaultResult + showsPrec d arr@(Ranked marr) = + let sh = show (toList (rshape arr)) + in showsMixedArray ("rfromListLinear " ++ sh) ("rreplicate " ++ sh) d marr instance Elt a => NFData (Ranked n a) where rnf (Ranked arr) = rnf arr @@ -152,7 +144,7 @@ instance Elt a => Elt (Ranked n a) where mshowShapeTree _ (sh, t) = "(" ++ show sh ++ ", " ++ mshowShapeTree (Proxy @a) t ++ ")" - mstrideTree (M_Ranked arr) = mstrideTree arr + marrayStrides (M_Ranked arr) = marrayStrides arr mvecsWrite :: forall sh s. IShX sh -> IIxX sh -> Ranked n a -> MixedVecs s sh (Ranked n a) -> ST s () mvecsWrite sh idx (Ranked arr) vecs = -- cgit v1.2.3-70-g09d2