From 46af04ce96ba9c9b0067039c822427db71074e57 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 14 Jun 2024 12:13:16 +0200 Subject: Show instances via toListLinear --- src/Data/Array/Nested/Internal/Shaped.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/Data/Array/Nested/Internal/Shaped.hs') diff --git a/src/Data/Array/Nested/Internal/Shaped.hs b/src/Data/Array/Nested/Internal/Shaped.hs index 9abce4f..be56030 100644 --- a/src/Data/Array/Nested/Internal/Shaped.hs +++ b/src/Data/Array/Nested/Internal/Shaped.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE DerivingVia #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} @@ -59,14 +60,18 @@ import Data.Array.Nested.Internal.Shape -- 'Shaped' is a newtype around a 'Mixed' of 'Just's. 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 (MapJust sh) a) => Ord (Shaped sh a) deriving instance NFData (Mixed (MapJust sh) a) => NFData (Shaped sh a) +instance (Show a, Elt a) => Show (Shaped sh a) where + showsPrec d arr = showParen (d > 10) $ + showString "sfromListLinear " . shows (shsToList (sshape arr)) . showString " " + . shows (stoListLinear arr) + -- just unwrap the newtype and defer to the general instance for nested arrays newtype instance Mixed sh (Shaped sh' a) = M_Shaped (Mixed sh (Mixed (MapJust sh') a)) -deriving instance Show (Mixed sh (Mixed (MapJust sh') a)) => Show (Mixed sh (Shaped sh' a)) +deriving via (ShowViaToListLinear sh (Shaped sh' a)) instance (Show a, Elt a) => Show (Mixed sh (Shaped sh' a)) newtype instance MixedVecs s sh (Shaped sh' a) = MV_Shaped (MixedVecs s sh (Mixed (MapJust sh') a)) -- cgit v1.2.3-70-g09d2