diff options
author | Tom Smeding <tom@tomsmeding.com> | 2024-06-14 12:13:16 +0200 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2024-06-14 12:13:16 +0200 |
commit | 46af04ce96ba9c9b0067039c822427db71074e57 (patch) | |
tree | b75093b70b0eabdd00073e25332f02d73c74f7f8 /src/Data/Array/Nested/Internal/Shaped.hs | |
parent | 827ffbfe7e346750936fee0e65e41bb524d97164 (diff) |
Show instances via toListLinear
Diffstat (limited to 'src/Data/Array/Nested/Internal/Shaped.hs')
-rw-r--r-- | src/Data/Array/Nested/Internal/Shaped.hs | 9 |
1 files changed, 7 insertions, 2 deletions
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)) |