vector-sized 0.4.0.1 → 0.4.1.0
raw patch · 5 files changed
+84/−2 lines, 5 files
Files
- changelog.md +3/−0
- src/Data/Vector/Generic/Sized.hs +27/−1
- src/Data/Vector/Sized.hs +25/−0
- src/Data/Vector/Storable/Sized.hs +28/−0
- vector-sized.cabal +1/−1
changelog.md view
@@ -1,5 +1,8 @@ # Change Log +## [0.4.1.0] - 2016-11-24+- Add `withSized` and `withSizedList`+ ## [0.4.0.1] - 2016-11-12 - Raise lower bound on base to 4.9
src/Data/Vector/Generic/Sized.hs view
@@ -8,6 +8,7 @@ {-# LANGUAGE KindSignatures #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeOperators #-}+{-# LANGUAGE RankNTypes #-} {-| This module reexports the functionality in 'Data.Vector.Generic' which maps well@@ -212,10 +213,12 @@ , fromList , fromListN , fromListN'+ , withSizedList -- ** Other Vector types , convert -- ** Unsized Vectors , toSized+ , withSized , fromSized , withVectorUnsafe ) where@@ -1525,6 +1528,17 @@ fromListN' _ = fromListN {-# inline fromListN' #-} +-- | /O(n)/ Takes a list and returns a continuation providing a vector with+-- a size parameter corresponding to the length of the list.+--+-- Essentially converts a list into a vector with the proper size+-- parameter, determined at runtime.+--+-- See 'withSized'+withSizedList :: forall v a r. VG.Vector v a+ => [a] -> (forall n. KnownNat n => Vector v n a -> r) -> r+withSizedList xs = withSized (VG.fromList xs)+ -- ** Different Vector types -- | /O(n)/ Convert different vector types@@ -1545,6 +1559,19 @@ where n' = natVal (Proxy :: Proxy n) {-# inline toSized #-} +-- | Takes a 'Data.Vector.Generic.Vector' and returns a continuation+-- providing a 'Data.Vector.Generic.Sized' with a size parameter @n@ that+-- is determined at runtime based on the length of the input vector.+--+-- Essentially converts a 'Data.Vector.Generic.Vector' into+-- a 'Data.Vector.Generic.Sized.Vector' with the correct size parameter+-- @n@.+withSized :: forall v a r. VG.Vector v a+ => v a -> (forall n. KnownNat n => Vector v n a -> r) -> r+withSized v f = case someNatVal (fromIntegral (VG.length v)) of+ Just (SomeNat (Proxy :: Proxy n)) -> f (Vector v :: Vector v n a)+ Nothing -> error "withSized: VG.length returned negative length."+ fromSized :: Vector v n a -> v a fromSized (Vector v) = v {-# inline fromSized #-}@@ -1555,4 +1582,3 @@ => (v a -> w b) -> Vector v n a -> Vector w n b withVectorUnsafe f (Vector v) = Vector (f v) {-# inline withVectorUnsafe #-}-
src/Data/Vector/Sized.hs view
@@ -5,6 +5,7 @@ {-# LANGUAGE KindSignatures #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeOperators #-}+{-# LANGUAGE RankNTypes #-} {-| This module re-exports the functionality in 'Data.Vector.Generic.Sized'@@ -209,8 +210,10 @@ , fromList , fromListN , fromListN'+ , withSizedList -- ** Unsized Vectors , toSized+ , withSized , fromSized , withVectorUnsafe ) where@@ -1392,6 +1395,17 @@ fromListN' = V.fromListN' {-# inline fromListN' #-} +-- | /O(n)/ Takes a list and returns a continuation providing a vector with+-- a size parameter corresponding to the length of the list.+--+-- Essentially converts a list into a vector with the proper size+-- parameter, determined at runtime.+--+-- See 'withSized'+withSizedList :: forall a r. [a] -> (forall n. KnownNat n => Vector n a -> r) -> r+withSizedList xs = withSized (VU.fromList xs)+{-# inline withSizedList #-}+ -- ** Unsized vectors -- | Convert a 'Data.Vector.Generic.Vector' into a@@ -1401,6 +1415,17 @@ => VU.Vector a -> Maybe (Vector n a) toSized = V.toSized {-# inline toSized #-}++-- | Takes a 'Data.Vector.Vector' and returns a continuation providing+-- a 'Data.Vector.Sized.Vector' with a size parameter @n@ that is+-- determined at runtime based on the length of the input vector.+--+-- Essentially converts a 'Data.Vector.Vector' into+-- a 'Data.Vector.Sized.Vector' with the correct size parameter+-- @n@.+withSized :: forall a r. VU.Vector a -> (forall n. KnownNat n => Vector n a -> r) -> r+withSized = V.withSized+{-# inline withSized #-} fromSized :: Vector n a -> VU.Vector a fromSized = V.fromSized
src/Data/Vector/Storable/Sized.hs view
@@ -5,6 +5,7 @@ {-# LANGUAGE KindSignatures #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeOperators #-}+{-# LANGUAGE RankNTypes #-} {-| This module re-exports the functionality in 'Data.Vector.Generic.Sized'@@ -209,8 +210,10 @@ , fromList , fromListN , fromListN'+ , withSizedList -- ** Unsized Vectors , toSized+ , withSized , fromSized , withVectorUnsafe ) where@@ -1447,6 +1450,18 @@ fromListN' = V.fromListN' {-# inline fromListN' #-} +-- | /O(n)/ Takes a list and returns a continuation providing a vector with+-- a size parameter corresponding to the length of the list.+--+-- Essentially converts a list into a vector with the proper size+-- parameter, determined at runtime.+--+-- See 'withSized'+withSizedList :: forall a r. Storable a+ => [a] -> (forall n. KnownNat n => Vector n a -> r) -> r+withSizedList xs = withSized (VS.fromList xs)+{-# inline withSizedList #-}+ -- ** Unsized vectors -- | Convert a 'Data.Vector.Generic.Vector' into a@@ -1456,6 +1471,19 @@ => VS.Vector a -> Maybe (Vector n a) toSized = V.toSized {-# inline toSized #-}++-- | Takes a 'Data.Vector.Storable.Vector' and returns a continuation+-- providing a 'Data.Vector.Storable.Sized.Vector' with a size parameter+-- @n@ that is determined at runtime based on the length of the input+-- vector.+--+-- Essentially converts a 'Data.Vector.Storable.Vector' into+-- a 'Data.Vector.Storable.Sized.Vector' with the correct size parameter+-- @n@.+withSized :: forall a r. Storable a+ => VS.Vector a -> (forall n. KnownNat n => Vector n a -> r) -> r+withSized = V.withSized+{-# inline withSized #-} fromSized :: Vector n a -> VS.Vector a fromSized = V.fromSized
vector-sized.cabal view
@@ -1,5 +1,5 @@ name: vector-sized-version: 0.4.0.1+version: 0.4.1.0 synopsis: Size tagged vectors description: Please see README.md homepage: http://github.com/expipiplus1/vector-sized#readme