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/Base.hs | |
parent | 8890526cac9e6c4d5583d00fce55f32ba613cf31 (diff) |
default-show-instances flag
Diffstat (limited to 'src/Data/Array/Nested/Ranked/Base.hs')
-rw-r--r-- | src/Data/Array/Nested/Ranked/Base.hs | 14 |
1 files changed, 13 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)) |