From 78419dac665ccf8bacc6290c0d7749b6d6650288 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Mon, 22 Dec 2025 17:28:47 +0300 Subject: [PATCH 1/3] Make type family Dim polykinded This is needed for creating new API with support for vector not polymorphic in element type --- fixed-vector/Data/Vector/Fixed/Cont.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fixed-vector/Data/Vector/Fixed/Cont.hs b/fixed-vector/Data/Vector/Fixed/Cont.hs index 3efdbcd..2e87956 100644 --- a/fixed-vector/Data/Vector/Fixed/Cont.hs +++ b/fixed-vector/Data/Vector/Fixed/Cont.hs @@ -435,7 +435,7 @@ dimapFun fA fR fun ---------------------------------------------------------------- -- | Size of vector expressed as Peano natural. -type family Dim (v :: Type -> Type) :: PeanoNum +type family Dim (v :: k) :: PeanoNum -- | Type class for vectors with fixed length. Instance should provide -- two functions: one to create vector from @N@ elements and another From de69fa459baad1b896dff8bc39b0f703c72cdfaa Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Thu, 1 Jan 2026 17:18:57 +0300 Subject: [PATCH 2/3] Add Dim instance for vector type of kind Type That's for benefit of new not yet implemented API --- fixed-vector/Data/Vector/Fixed.hs | 15 +++++++---- fixed-vector/Data/Vector/Fixed/Boxed.hs | 7 ++--- fixed-vector/Data/Vector/Fixed/Cont.hs | 30 ++++++++++++++------- fixed-vector/Data/Vector/Fixed/Primitive.hs | 7 ++--- fixed-vector/Data/Vector/Fixed/Storable.hs | 7 ++--- fixed-vector/Data/Vector/Fixed/Strict.hs | 7 ++--- fixed-vector/Data/Vector/Fixed/Unboxed.hs | 15 +++++++---- 7 files changed, 56 insertions(+), 32 deletions(-) diff --git a/fixed-vector/Data/Vector/Fixed.hs b/fixed-vector/Data/Vector/Fixed.hs index f36023b..aa8009a 100644 --- a/fixed-vector/Data/Vector/Fixed.hs +++ b/fixed-vector/Data/Vector/Fixed.hs @@ -261,8 +261,10 @@ data VecPeano (n :: PeanoNum) a where Nil :: VecPeano 'Z a Cons :: a -> VecPeano n a -> VecPeano ('S n) a -type instance Dim (VecList n) = C.Peano n -type instance Dim (VecPeano n) = n +type instance Dim (VecList n) = C.Peano n +type instance Dim (VecList n a) = C.Peano n +type instance Dim (VecPeano n) = n +type instance Dim (VecPeano n a) = n instance Arity n => Vector (VecList n) a where construct = VecList <$> construct @(VecPeano (C.Peano n)) @a @@ -365,7 +367,8 @@ instance (Semigroup a) => Semigroup (Only a) where instance NFData a => NFData (Only a) where rnf (Only a) = rnf a -type instance Dim Only = C.N1 +type instance Dim Only = C.N1 +type instance Dim (Only a) = C.N1 instance Vector Only a where construct = Fun Only @@ -387,7 +390,8 @@ data Empty a = Empty instance NFData (Empty a) where rnf Empty = () -type instance Dim Empty = 'Z +type instance Dim Empty = 'Z +type instance Dim (Empty a) = 'Z instance Vector Empty a where construct = Fun Empty @@ -410,7 +414,8 @@ type Tuple5 a = (a,a,a,a,a) -- 'Storable', 'NFData', 'Functor', 'Applicative', 'Foldable'. newtype ViaFixed v a = ViaFixed (v a) -type instance Dim (ViaFixed v) = Dim v +type instance Dim (ViaFixed v) = Dim v +type instance Dim (ViaFixed v a) = Dim v instance Vector v a => Vector (ViaFixed v) a where construct = ViaFixed <$> construct diff --git a/fixed-vector/Data/Vector/Fixed/Boxed.hs b/fixed-vector/Data/Vector/Fixed/Boxed.hs index 25abe50..adca4e5 100644 --- a/fixed-vector/Data/Vector/Fixed/Boxed.hs +++ b/fixed-vector/Data/Vector/Fixed/Boxed.hs @@ -55,9 +55,10 @@ type Vec3 = Vec 3 type Vec4 = Vec 4 type Vec5 = Vec 5 -type instance Mutable (Vec n) = MVec n -type instance Dim (Vec n) = Peano n -type instance DimM (MVec n) = Peano n +type instance Mutable (Vec n) = MVec n +type instance Dim (Vec n) = Peano n +type instance Dim (Vec n a) = Peano n +type instance DimM (MVec n) = Peano n ---------------------------------------------------------------- diff --git a/fixed-vector/Data/Vector/Fixed/Cont.hs b/fixed-vector/Data/Vector/Fixed/Cont.hs index 2e87956..8112647 100644 --- a/fixed-vector/Data/Vector/Fixed/Cont.hs +++ b/fixed-vector/Data/Vector/Fixed/Cont.hs @@ -478,7 +478,8 @@ length _ = peanoToInt (proxy# @(Dim v)) -- Church encoded N-element vector. newtype ContVec n a = ContVec (forall r. Fun n a r -> r) -type instance Dim (ContVec n) = n +type instance Dim (ContVec n) = n +type instance Dim (ContVec n a) = n -- | Cons values to the @ContVec@. consPeano :: a -> ContVec n a -> ContVec ('S n) a @@ -1301,7 +1302,8 @@ gfoldlF f c0 = accum -- Instances ---------------------------------------------------------------- -type instance Dim Complex = N2 +type instance Dim Complex = N2 +type instance Dim (Complex a) = N2 instance Vector Complex a where construct = Fun (:+) @@ -1310,7 +1312,8 @@ instance Vector Complex a where {-# INLINE inspect #-} -type instance Dim Identity = N1 +type instance Dim Identity = N1 +type instance Dim (Identity a) = N1 instance Vector Identity a where construct = Fun Identity @@ -1319,7 +1322,8 @@ instance Vector Identity a where {-# INLINE inspect #-} -type instance Dim ((,) a) = N2 +type instance Dim ((,) a) = N2 +type instance Dim ((,) a b) = N2 -- | Note this instance (and other instances for tuples) is -- essentially monomorphic in element type. Vector type /v/ of 2 @@ -1332,7 +1336,8 @@ instance (b~a) => Vector ((,) b) a where {-# INLINE inspect #-} -type instance Dim ((,,) a b) = N3 +type instance Dim ((,,) a b) = N3 +type instance Dim ((,,) a b c) = N3 instance (b~a, c~a) => Vector ((,,) b c) a where construct = Fun (,,) @@ -1341,7 +1346,8 @@ instance (b~a, c~a) => Vector ((,,) b c) a where {-# INLINE inspect #-} -type instance Dim ((,,,) a b c) = N4 +type instance Dim ((,,,) a b c) = N4 +type instance Dim ((,,,) a b c d) = N4 instance (b~a, c~a, d~a) => Vector ((,,,) b c d) a where construct = Fun (,,,) @@ -1350,7 +1356,8 @@ instance (b~a, c~a, d~a) => Vector ((,,,) b c d) a where {-# INLINE inspect #-} -type instance Dim ((,,,,) a b c d) = N5 +type instance Dim ((,,,,) a b c d) = N5 +type instance Dim ((,,,,) a b c d e) = N5 instance (b~a, c~a, d~a, e~a) => Vector ((,,,,) b c d e) a where construct = Fun (,,,,) @@ -1359,7 +1366,8 @@ instance (b~a, c~a, d~a, e~a) => Vector ((,,,,) b c d e) a where {-# INLINE inspect #-} -type instance Dim ((,,,,,) a b c d e) = N6 +type instance Dim ((,,,,,) a b c d e) = N6 +type instance Dim ((,,,,,) a b c d e f) = N6 instance (b~a, c~a, d~a, e~a, f~a) => Vector ((,,,,,) b c d e f) a where construct = Fun (,,,,,) @@ -1368,7 +1376,8 @@ instance (b~a, c~a, d~a, e~a, f~a) => Vector ((,,,,,) b c d e f) a where {-# INLINE inspect #-} -type instance Dim ((,,,,,,) a b c d e f) = N7 +type instance Dim ((,,,,,,) a b c d e f) = N7 +type instance Dim ((,,,,,,) a b c d e f g) = N7 instance (b~a, c~a, d~a, e~a, f~a, g~a) => Vector ((,,,,,,) b c d e f g) a where construct = Fun (,,,,,,) @@ -1376,7 +1385,8 @@ instance (b~a, c~a, d~a, e~a, f~a, g~a) => Vector ((,,,,,,) b c d e f g) a where {-# INLINE construct #-} {-# INLINE inspect #-} -type instance Dim Proxy = Z +type instance Dim Proxy = Z +type instance Dim (Proxy a) = Z instance Vector Proxy a where construct = Fun Proxy diff --git a/fixed-vector/Data/Vector/Fixed/Primitive.hs b/fixed-vector/Data/Vector/Fixed/Primitive.hs index ae71f4b..1326744 100644 --- a/fixed-vector/Data/Vector/Fixed/Primitive.hs +++ b/fixed-vector/Data/Vector/Fixed/Primitive.hs @@ -56,9 +56,10 @@ type Vec3 = Vec 3 type Vec4 = Vec 4 type Vec5 = Vec 5 -type instance Mutable (Vec n) = MVec n -type instance Dim (Vec n) = Peano n -type instance DimM (MVec n) = Peano n +type instance Mutable (Vec n) = MVec n +type instance Dim (Vec n) = Peano n +type instance Dim (Vec n a) = Peano n +type instance DimM (MVec n) = Peano n ---------------------------------------------------------------- diff --git a/fixed-vector/Data/Vector/Fixed/Storable.hs b/fixed-vector/Data/Vector/Fixed/Storable.hs index 08ee0fb..0e9fade 100644 --- a/fixed-vector/Data/Vector/Fixed/Storable.hs +++ b/fixed-vector/Data/Vector/Fixed/Storable.hs @@ -62,9 +62,10 @@ type Vec3 = Vec 3 type Vec4 = Vec 4 type Vec5 = Vec 5 -type instance Mutable (Vec n) = MVec n -type instance Dim (Vec n) = Peano n -type instance DimM (MVec n) = Peano n +type instance Mutable (Vec n) = MVec n +type instance Dim (Vec n) = Peano n +type instance Dim (Vec n a) = Peano n +type instance DimM (MVec n) = Peano n ---------------------------------------------------------------- diff --git a/fixed-vector/Data/Vector/Fixed/Strict.hs b/fixed-vector/Data/Vector/Fixed/Strict.hs index b309400..fbc7fb0 100644 --- a/fixed-vector/Data/Vector/Fixed/Strict.hs +++ b/fixed-vector/Data/Vector/Fixed/Strict.hs @@ -45,9 +45,10 @@ type Vec3 = Vec 3 type Vec4 = Vec 4 type Vec5 = Vec 5 -type instance Mutable (Vec n) = MVec n -type instance Dim (Vec n) = Peano n -type instance DimM (MVec n) = Peano n +type instance Mutable (Vec n) = MVec n +type instance Dim (Vec n) = Peano n +type instance Dim (Vec n a) = Peano n +type instance DimM (MVec n) = Peano n ---------------------------------------------------------------- diff --git a/fixed-vector/Data/Vector/Fixed/Unboxed.hs b/fixed-vector/Data/Vector/Fixed/Unboxed.hs index d1cf28d..b332797 100644 --- a/fixed-vector/Data/Vector/Fixed/Unboxed.hs +++ b/fixed-vector/Data/Vector/Fixed/Unboxed.hs @@ -86,7 +86,8 @@ class ( Dim (VecRepr n a) ~ Peano n -- | Convert element from its representation fromEltRepr :: Proxy# n -> EltRepr a -> a -type instance Dim (Vec n) = Peano n +type instance Dim (Vec n) = Peano n +type instance Dim (Vec n a) = Peano n instance (Arity n, Unbox n a) => Vector (Vec n) a where inspect (Vec v) f @@ -141,7 +142,8 @@ instance F.Arity n => Unbox n () where data VecUnit (n :: Nat) a = VecUnit -type instance Dim (VecUnit n) = Peano n +type instance Dim (VecUnit n) = Peano n +type instance Dim (VecUnit n a) = Peano n instance F.Arity n => Vector (VecUnit n) () where inspect _ fun @@ -162,7 +164,8 @@ instance F.Arity n => Vector (VecUnit n) () where -- GHC quite a bit. data BitVec (n :: Nat) a = BitVec Word64 -type instance Dim (BitVec n) = Peano n +type instance Dim (BitVec n) = Peano n +type instance Dim (BitVec n a) = Peano n instance (n <= 64, Arity n, a ~ Bool) => Vector (BitVec n) a where inspect (BitVec w) = inspect (C.generate (testBit w)) @@ -238,7 +241,8 @@ deriving newtype instance (n <= 64, Arity n) => Unbox n Any -- | Representation for vector of 2-tuple as two vectors. data T2 n a b x = T2 !(Vec n a) !(Vec n b) -type instance Dim (T2 n a b) = Peano n +type instance Dim (T2 n a b) = Peano n +type instance Dim (T2 n a b x) = Peano n instance (Arity n, Unbox n a, Unbox n b) => Vector (T2 n a b) (a,b) where inspect (T2 vA vB) @@ -268,7 +272,8 @@ data T_pair a b x y n = T_pair (Fun n a x) (Fun n b y) -- | Representation for vector of 2-tuple as two vectors. data T3 n a b c x = T3 !(Vec n a) !(Vec n b) !(Vec n c) -type instance Dim (T3 n a b c) = Peano n +type instance Dim (T3 n a b c) = Peano n +type instance Dim (T3 n a b c x) = Peano n instance (Arity n, Unbox n a, Unbox n b, Unbox n c) => Vector (T3 n a b c) (a,b,c) where inspect (T3 vA vB vC) From 3683c942b2fc7cc039215c9220ce5625f3f5e7de Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Tue, 20 Jan 2026 22:54:25 +0300 Subject: [PATCH 3/3] CI fix --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 468faf4..d4d63f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,6 +73,7 @@ jobs: - name: cabal check run: | for nm in fixed-vector-*; do (cd $nm; cabal check); done + working-directory: ./unpacked # ---------------- - name: Build run: | @@ -81,7 +82,9 @@ jobs: if [ "${{ matrix.skip-bench }}" == "" ]; then FLAG_BENCH=--enable-benchmarks; fi cabal configure $FLAG_TEST $FLAG_BENCH cabal build all --write-ghc-environment-files=always + working-directory: ./unpacked # ---------------- - name: Test run: | cabal test all + working-directory: ./unpacked