summaryrefslogtreecommitdiff
path: root/src/Data/Array/Nested/Internal.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-05-13 19:45:35 +0200
committerTom Smeding <tom@tomsmeding.com>2024-05-13 19:46:25 +0200
commit7501414935c8f24d5e132405dd897d46e240b692 (patch)
treee92304e338908c9668d6645ed5b007190811a861 /src/Data/Array/Nested/Internal.hs
parent8a8a9eda7af43770f35b7f1078566d388b34b9a7 (diff)
Annotate all lists of primitive element types in the source
Diffstat (limited to 'src/Data/Array/Nested/Internal.hs')
-rw-r--r--src/Data/Array/Nested/Internal.hs17
1 files changed, 17 insertions, 0 deletions
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)