From 7501414935c8f24d5e132405dd897d46e240b692 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Mon, 13 May 2024 19:45:35 +0200 Subject: Annotate all lists of primitive element types in the source --- src/Data/Array/Nested/Internal.hs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/Data/Array/Nested/Internal.hs b/src/Data/Array/Nested/Internal.hs index 6f22e59..4577967 100644 --- a/src/Data/Array/Nested/Internal.hs +++ b/src/Data/Array/Nested/Internal.hs @@ -79,6 +79,16 @@ import Data.INat -- -> no, because mlift and also any kind of internals probing from outsiders +-- Primitive element types +-- ======================= +-- +-- There are a few primitive element types; arrays containing elements of such +-- type are a newtype over an XArray, which it itself a newtype over a Vector. +-- Unfortunately, the setup of the library requires us to list these primitive +-- element types multiple times; to aid in extending the list, all these lists +-- have been marked with [PRIMITIVE ELEMENT TYPES LIST]. + + type family Replicate n a where Replicate Z a = '[] Replicate (S n) a = a : Replicate n a @@ -141,6 +151,7 @@ data family Mixed sh a newtype instance Mixed sh (Primitive a) = M_Primitive (XArray sh a) deriving (Show) +-- [PRIMITIVE ELEMENT TYPES LIST] newtype instance Mixed sh Int = M_Int (XArray sh Int) deriving (Show) newtype instance Mixed sh Double = M_Double (XArray sh Double) @@ -164,6 +175,7 @@ data family MixedVecs s sh a newtype instance MixedVecs s sh (Primitive a) = MV_Primitive (VS.MVector s a) +-- [PRIMITIVE ELEMENT TYPES LIST] newtype instance MixedVecs s sh Int = MV_Int (VS.MVector s Int) newtype instance MixedVecs s sh Double = MV_Double (VS.MVector s Double) newtype instance MixedVecs s sh () = MV_Nil (VS.MVector s ()) -- no content, MVector optimises this @@ -178,6 +190,7 @@ data instance MixedVecs s sh1 (Mixed sh2 a) = MV_Nest !(IIxX sh2) !(MixedVecs s -- | Tree giving the shape of every array component. type family ShapeTree a where ShapeTree (Primitive _) = () + -- [PRIMITIVE ELEMENT TYPES LIST] ShapeTree Int = () ShapeTree Double = () ShapeTree () = () @@ -306,6 +319,7 @@ instance Storable a => Elt (Primitive a) where mvecsFreeze sh (MV_Primitive v) = M_Primitive . X.fromVector sh <$> VS.freeze v +-- [PRIMITIVE ELEMENT TYPES LIST] deriving via Primitive Int instance Elt Int deriving via Primitive Double instance Elt Double deriving via Primitive () instance Elt () @@ -548,6 +562,7 @@ instance (KnownShapeX sh, Storable a, Num a) => Num (Mixed sh (Primitive a)) whe Nothing -> error "Data.Array.Nested.fromIntegral: \ \Unknown components in shape, use explicit mconstant" +-- [PRIMITIVE ELEMENT TYPES LIST] (really, a partial list of just the numeric types) deriving via Mixed sh (Primitive Int) instance KnownShapeX sh => Num (Mixed sh Int) deriving via Mixed sh (Primitive Double) instance KnownShapeX sh => Num (Mixed sh Double) @@ -850,6 +865,7 @@ instance (KnownINat n, Storable a, Num a) => Num (Ranked n (Primitive a)) where SS _ -> error "Data.Array.Nested.fromIntegral(Ranked): \ \Rank non-zero, use explicit mconstant" +-- [PRIMITIVE ELEMENT TYPES LIST] (really, a partial list of just the numeric types) deriving via Ranked n (Primitive Int) instance KnownINat n => Num (Ranked n Int) deriving via Ranked n (Primitive Double) instance KnownINat n => Num (Ranked n Double) @@ -1067,6 +1083,7 @@ instance (KnownShape sh, Storable a, Num a) => Num (Shaped sh (Primitive a)) whe signum = arithPromoteShaped signum fromInteger n = sconstantP (fromInteger n) +-- [PRIMITIVE ELEMENT TYPES LIST] (really, a partial list of just the numeric types) deriving via Shaped sh (Primitive Int) instance KnownShape sh => Num (Shaped sh Int) deriving via Shaped sh (Primitive Double) instance KnownShape sh => Num (Shaped sh Double) -- cgit v1.2.3-70-g09d2