diff options
author | Tom Smeding <tom@tomsmeding.com> | 2025-05-16 10:42:24 +0200 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2025-05-16 11:21:51 +0200 |
commit | 09041ca155485885a2f337f71b04442e991a550d (patch) | |
tree | 82c05989d2be6d87ca96aa7467f3162bf2d5698b /src/Data/Array/Nested/Ranked | |
parent | 8890526cac9e6c4d5583d00fce55f32ba613cf31 (diff) |
default-show-instances flag
Diffstat (limited to 'src/Data/Array/Nested/Ranked')
-rw-r--r-- | src/Data/Array/Nested/Ranked/Base.hs | 14 | ||||
-rw-r--r-- | src/Data/Array/Nested/Ranked/Shape.hs | 13 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/Data/Array/Nested/Ranked/Base.hs b/src/Data/Array/Nested/Ranked/Base.hs index f827187..ce7025d 100644 --- a/src/Data/Array/Nested/Ranked/Base.hs +++ b/src/Data/Array/Nested/Ranked/Base.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleContexts #-} @@ -21,7 +22,6 @@ import Control.DeepSeq (NFData(..)) import Control.Monad.ST import Data.Bifunctor (first) import Data.Coerce (coerce) -import Data.Foldable (toList) import Data.Kind (Type) import Data.List.NonEmpty (NonEmpty) import Data.Proxy @@ -30,6 +30,10 @@ import GHC.Float qualified (expm1, log1mexp, log1p, log1pexp) import GHC.Generics (Generic) import GHC.TypeLits +#ifndef OXAR_DEFAULT_SHOW_INSTANCES +import Data.Foldable (toList) +#endif + import Data.Array.Mixed.Lemmas import Data.Array.Mixed.Types import Data.Array.XArray (XArray(..)) @@ -50,13 +54,18 @@ import Data.Array.Strided.Arith -- 'Ranked' is a newtype around a 'Mixed' of 'Nothing's. type Ranked :: Nat -> Type -> Type newtype Ranked n a = Ranked (Mixed (Replicate n Nothing) a) +#ifdef OXAR_DEFAULT_SHOW_INSTANCES +deriving instance Show (Mixed (Replicate n Nothing) a) => Show (Ranked n a) +#endif deriving instance Eq (Mixed (Replicate n Nothing) a) => Eq (Ranked n a) deriving instance Ord (Mixed (Replicate n Nothing) a) => Ord (Ranked n a) +#ifndef OXAR_DEFAULT_SHOW_INSTANCES instance (Show a, Elt a) => Show (Ranked n a) where showsPrec d arr@(Ranked marr) = let sh = show (toList (rshape arr)) in showsMixedArray ("rfromListLinear " ++ sh) ("rreplicate " ++ sh) d marr +#endif instance Elt a => NFData (Ranked n a) where rnf (Ranked arr) = rnf arr @@ -64,6 +73,9 @@ instance Elt a => NFData (Ranked n a) where -- just unwrap the newtype and defer to the general instance for nested arrays newtype instance Mixed sh (Ranked n a) = M_Ranked (Mixed sh (Mixed (Replicate n Nothing) a)) deriving (Generic) +#ifdef OXAR_DEFAULT_SHOW_INSTANCES +deriving instance Show (Mixed sh (Mixed (Replicate n Nothing) a)) => Show (Mixed sh (Ranked n a)) +#endif deriving instance Eq (Mixed sh (Mixed (Replicate n Nothing) a)) => Eq (Mixed sh (Ranked n a)) diff --git a/src/Data/Array/Nested/Ranked/Shape.hs b/src/Data/Array/Nested/Ranked/Shape.hs index 1c0b9eb..c18f9ee 100644 --- a/src/Data/Array/Nested/Ranked/Shape.hs +++ b/src/Data/Array/Nested/Ranked/Shape.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveFoldable #-} {-# LANGUAGE DeriveFunctor #-} @@ -54,8 +55,12 @@ deriving instance Functor (ListR n) deriving instance Foldable (ListR n) infixr 3 ::: +#ifdef OXAR_DEFAULT_SHOW_INSTANCES +deriving instance Show i => Show (ListR n i) +#else instance Show i => Show (ListR n i) where showsPrec _ = listrShow shows +#endif instance NFData i => NFData (ListR n i) where rnf ZR = () @@ -189,8 +194,12 @@ infixr 3 :.: type IIxR n = IxR n Int +#ifdef OXAR_DEFAULT_SHOW_INSTANCES +deriving instance Show i => Show (IxR n i) +#else instance Show i => Show (IxR n i) where showsPrec _ (IxR l) = listrShow shows l +#endif instance NFData i => NFData (IxR sh i) @@ -260,8 +269,12 @@ infixr 3 :$: type IShR n = ShR n Int +#ifdef OXAR_DEFAULT_SHOW_INSTANCES +deriving instance Show i => Show (ShR n i) +#else instance Show i => Show (ShR n i) where showsPrec _ (ShR l) = listrShow shows l +#endif instance NFData i => NFData (ShR sh i) |