Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
15 changes: 10 additions & 5 deletions fixed-vector/Data/Vector/Fixed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions fixed-vector/Data/Vector/Fixed/Boxed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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


----------------------------------------------------------------
Expand Down
32 changes: 21 additions & 11 deletions fixed-vector/Data/Vector/Fixed/Cont.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 (:+)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 (,,)
Expand All @@ -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 (,,,)
Expand All @@ -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 (,,,,)
Expand All @@ -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 (,,,,,)
Expand All @@ -1368,15 +1376,17 @@ 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 (,,,,,,)
inspect (a,b,c,d,e,f,g) (Fun fun) = fun a b c d e f g
{-# 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
Expand Down
7 changes: 4 additions & 3 deletions fixed-vector/Data/Vector/Fixed/Primitive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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


----------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions fixed-vector/Data/Vector/Fixed/Storable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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


----------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions fixed-vector/Data/Vector/Fixed/Strict.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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


----------------------------------------------------------------
Expand Down
15 changes: 10 additions & 5 deletions fixed-vector/Data/Vector/Fixed/Unboxed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading