sized-vector 1.1.0.0 → 1.2.0.0
raw patch · 2 files changed
+14/−23 lines, 2 filesdep ~type-natural
Dependency ranges changed: type-natural
Files
- Data/Vector/Sized.hs +12/−21
- sized-vector.cabal +2/−2
Data/Vector/Sized.hs view
@@ -5,8 +5,9 @@ {-# LANGUAGE TypeOperators, NoImplicitPrelude #-} -- | Size-parameterized vector types and functions. module Data.Vector.Sized ( -- * Vectors and indices- Vector (..)- , Index(..), succIndex, indexToInt,+ Vector (..), Index,+ -- ** Re-exports+ module Data.Type.Ordinal, -- * Conversion & Construction replicate, replicate', singleton, uncons, -- ** List@@ -40,6 +41,7 @@ import Data.Maybe import Data.Type.Monomorphic import Data.Type.Natural hiding (promote)+import Data.Type.Ordinal import qualified Prelude as P import Prelude (Eq(..), Bool(..), Int, Show(..), (&&), Num(..) , (||), not, error, ($), (.), seq, fst, snd@@ -53,6 +55,9 @@ infixr 5 :- +-- | Type synonym for @Ordinal@.+type Index = Ordinal+ -- | Monomorphic representation of 'Vector' @a n@ is @[a]@. instance Monomorphicable (Vector a) where type MonomorphicRep (Vector a) = [a]@@ -62,20 +67,6 @@ case promote xs of Monomorphic vec -> Monomorphic $ x :- vec --- | Index type for list.-data Index (n :: Nat) where- Index :: ((S m :<<= n) ~ True) => SNat m -> Index n---- | Succ index number.-succIndex :: Index n -> Index (S n)-succIndex (Index n) = Index (sS n)---- | Convert index into integer.-indexToInt :: Index n -> Int-indexToInt (Index n) = sNatToInt n--deriving instance Show (Index n)- deriving instance Show a => Show (Vector a n) instance (Eq a) => Eq (Vector a n) where Nil == Nil = True@@ -344,8 +335,8 @@ -- | A 'Index' version of 'index'. sIndex :: Index n -> Vector a n -> a-sIndex (Index SZ) (x :- _) = x-sIndex (Index (SS n)) (_ :- xs) = sIndex (Index n) xs+sIndex OZ (x :- _) = x+sIndex (OS n) (_ :- xs) = sIndex n xs -- | The 'elemIndex' function returns the index (as 'Int') of the first element in the given list -- which is equal (by '==') to the query element, or Nothing if there is no such element.@@ -378,14 +369,14 @@ -- | The 'findIndices' function extends 'findIndex', by returning the indices of all elements satisfying the predicate, -- in ascending order. findIndices :: (a -> Bool) -> Vector a n -> [Int]-findIndices p = P.map indexToInt . sFindIndices p+findIndices p = P.map ordToInt . sFindIndices p -- | 'Index' version of 'findIndices'. sFindIndices :: (a -> Bool) -> Vector a n -> [Index n] sFindIndices _ Nil = [] sFindIndices p (x :- xs)- | p x = Index sZero : P.map succIndex (sFindIndices p xs)- | otherwise = P.map succIndex $ sFindIndices p xs+ | p x = OZ : P.map OS (sFindIndices p xs)+ | otherwise = P.map OS $ sFindIndices p xs -------------------------------------------------- -- Zipping vectors
sized-vector.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: sized-vector-version: 1.1.0.0+version: 1.2.0.0 synopsis: Size-parameterized vector types and functions. description: Size-parameterized vector types and functions using a data-type promotion. homepage: https://github.com/konn/sized-vector@@ -23,7 +23,7 @@ exposed-modules: Data.Vector.Sized build-depends: base >= 2.0 && < 5 , singletons == 0.8.*- , type-natural >= 0.0.2.0+ , type-natural >= 0.0.4.0 , monomorphic == 0.0.* , equational-reasoning == 0.0.* , hashable == 1.1.*