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/Shaped.hs | 8 ++++++-- 1 file changed, 6 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 efeb618..ece4272 100644 --- a/src/Data/Array/Nested/Internal/Shaped.hs +++ b/src/Data/Array/Nested/Internal/Shaped.hs @@ -20,7 +20,7 @@ module Data.Array.Nested.Internal.Shaped where import Prelude hiding (mappend, mconcat) -import Control.DeepSeq (NFData) +import Control.DeepSeq (NFData(..)) import Control.Monad.ST import Data.Array.Internal.ShapedS qualified as SS import Data.Array.Internal.ShapedG qualified as SG @@ -62,13 +62,15 @@ type Shaped :: [Nat] -> Type -> Type newtype Shaped sh a = Shaped (Mixed (MapJust 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) +instance Elt a => NFData (Shaped sh a) where + rnf (Shaped arr) = rnf 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)) @@ -123,6 +125,8 @@ instance Elt a => Elt (Shaped sh a) where mconcat l = M_Shaped (mconcat (coerce l)) + mrnf (M_Shaped arr) = mrnf arr + type ShapeTree (Shaped sh a) = (ShS sh, ShapeTree a) mshapeTree (Shaped arr) = first shCvtXS' (mshapeTree arr) -- cgit v1.2.3-70-g09d2