From 637ca0e7dd7db16233731b40ccbc7f4cb5c63a40 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Wed, 18 Dec 2024 22:12:06 +0100 Subject: Uniformise NFData instance (by putting rnf in Elt) This now depends on: https://github.com/augustss/orthotope/pull/14 My sincere apologies. --- src/Data/Array/Nested/Internal/Ranked.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 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 54094cc..b3d4f91 100644 --- a/src/Data/Array/Nested/Internal/Ranked.hs +++ b/src/Data/Array/Nested/Internal/Ranked.hs @@ -21,7 +21,7 @@ module Data.Array.Nested.Internal.Ranked where import Prelude hiding (mappend, mconcat) -import Control.DeepSeq (NFData) +import Control.DeepSeq (NFData(..)) import Control.Monad.ST import Data.Array.RankedS qualified as S import Data.Bifunctor (first) @@ -61,13 +61,15 @@ type Ranked :: Nat -> Type -> Type newtype Ranked n a = Ranked (Mixed (Replicate n Nothing) a) deriving instance Eq (Mixed (Replicate n Nothing) a) => Eq (Ranked n a) deriving instance Ord (Mixed (Replicate n Nothing) a) => Ord (Ranked n a) -deriving instance NFData (Mixed (Replicate n Nothing) a) => NFData (Ranked n a) instance (Show a, Elt a) => Show (Ranked n a) where showsPrec d arr = showParen (d > 10) $ showString "rfromListLinear " . shows (toList (rshape arr)) . showString " " . shows (rtoListLinear arr) +instance Elt a => NFData (Ranked n a) where + rnf (Ranked arr) = rnf arr + -- 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)) @@ -125,6 +127,8 @@ instance Elt a => Elt (Ranked n a) where mconcat l = M_Ranked (mconcat (coerce l)) + mrnf (M_Ranked arr) = mrnf arr + type ShapeTree (Ranked n a) = (IShR n, ShapeTree a) mshapeTree (Ranked arr) = first shCvtXR' (mshapeTree arr) -- cgit v1.2.3-70-g09d2