Skip to content

Commit

Permalink
Merge pull request #68 from kozross/koz-devel
Browse files Browse the repository at this point in the history
Adding Hashable instances, documentation edits, Brittany formatting, generalized concatMap
  • Loading branch information
kozross authored Dec 4, 2018
2 parents e410ee0 + 6633fa2 commit 1de05be
Show file tree
Hide file tree
Showing 13 changed files with 611 additions and 540 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ cabal.sandbox.config
*.aux
*.hp
.stack-work/
.nvimrc
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [1.2.0.0] - 2018-11-15

- Add ``Hashable`` instances
- Generalize ``concatMap``
- Various code and documentation cleanup

## [1.1.1.0] - 2018-11-13

- Fix build and add CI for 8.6.2
Expand Down
42 changes: 20 additions & 22 deletions src/Data/Vector/Generic/Mutable/Sized.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

{-|
This module reexports the functionality in 'Data.Vector.Generic.Mutable'
which maps well to explicity sized vectors.
which maps well to explicitly sized vectors.
Functions returning a vector determine the size from the type context
unless they have a @'@ suffix in which case they take an explicit 'Proxy'
argument.
Functions where the resultant vector size is not know until compile time
Functions where the resultant vector size is not known until runtime
are not exported.
-}

Expand Down Expand Up @@ -111,7 +111,7 @@ length' :: forall v n s a. ()
length' _ = Proxy
{-# inline length' #-}

-- | /O(1)/ Check whether the mutable vector is empty
-- | /O(1)/ Check whether the mutable vector is empty.
null :: forall v n s a. KnownNat n
=> MVector v n s a -> Bool
null _ = isJust $ Proxy @n `sameNat` Proxy @0
Expand Down Expand Up @@ -155,51 +155,51 @@ tail :: forall v n s a. VGM.MVector v a
tail (MVector v) = MVector (VGM.unsafeTail v)
{-# inline tail #-}

-- | /O(1)/ Yield the first n elements. The resultant vector always contains
-- this many elements. The length of the resultant vector is inferred from the
-- | /O(1)/ Yield the first @n@ elements. The resulting vector always contains
-- this many elements. The length of the resulting vector is inferred from the
-- type.
take :: forall v n k s a. (KnownNat n, VGM.MVector v a)
=> MVector v (n+k) s a -> MVector v n s a
take (MVector v) = MVector (VGM.unsafeTake i v)
where i = fromInteger (natVal (Proxy :: Proxy n))
{-# inline take #-}

-- | /O(1)/ Yield the first n elements. The resultant vector always contains
-- this many elements. The length of the resultant vector is given explicitly
-- | /O(1)/ Yield the first @n@ elements. The resulting vector always contains
-- this many elements. The length of the resulting vector is given explicitly
-- as a 'Proxy' argument.
take' :: forall v n k s a p. (KnownNat n, VGM.MVector v a)
=> p n -> MVector v (n+k) s a -> MVector v n s a
take' _ = take
{-# inline take' #-}

-- | /O(1)/ Yield all but the the first n elements. The given vector must
-- contain at least this many elements The length of the resultant vector is
-- | /O(1)/ Yield all but the the first @n@ elements. The given vector must
-- contain at least this many elements. The length of the resulting vector is
-- inferred from the type.
drop :: forall v n k s a. (KnownNat n, VGM.MVector v a)
=> MVector v (n+k) s a -> MVector v k s a
drop (MVector v) = MVector (VGM.unsafeDrop i v)
where i = fromInteger (natVal (Proxy :: Proxy n))
{-# inline drop #-}

-- | /O(1)/ Yield all but the the first n elements. The given vector must
-- contain at least this many elements The length of the resultant vector is
-- givel explicitly as a 'Proxy' argument.
-- | /O(1)/ Yield all but the the first @n@ elements. The given vector must
-- contain at least this many elements. The length of the resulting vector is
-- given explicitly as a 'Proxy' argument.
drop' :: forall v n k s a p. (KnownNat n, VGM.MVector v a)
=> p n -> MVector v (n+k) s a -> MVector v k s a
drop' _ = drop
{-# inline drop' #-}

-- | /O(1)/ Yield the first n elements paired with the remainder without copying.
-- The lengths of the resultant vector are inferred from the type.
-- | /O(1)/ Yield the first @n@ elements, paired with the rest, without copying.
-- The lengths of the resulting vectors are inferred from the type.
splitAt :: forall v n m s a. (KnownNat n, VGM.MVector v a)
=> MVector v (n+m) s a -> (MVector v n s a, MVector v m s a)
splitAt (MVector v) = (MVector a, MVector b)
where i = fromInteger (natVal (Proxy :: Proxy n))
(a, b) = VGM.splitAt i v
{-# inline splitAt #-}

-- | /O(1)/ Yield the first n elements paired with the remainder without
-- copying. The length of the first resultant vector is passed explicitly as a
-- | /O(1)/ Yield the first @n@ elements, paired with the rest, without
-- copying. The length of the first resulting vector is passed explicitly as a
-- 'Proxy' argument.
splitAt' :: forall v n m s a p. (KnownNat n, VGM.MVector v a)
=> p n -> MVector v (n+m) s a -> (MVector v n s a, MVector v m s a)
Expand All @@ -208,9 +208,7 @@ splitAt' _ = splitAt

-- ** Overlaps

-- | /O(1)/ Yield all but the the first n elements. The given vector must
-- contain at least this many elements The length of the resultant vector is
-- inferred from the type.
-- | /O(1)/ Check whether two vectors overlap.
overlaps :: forall v n k s a. VGM.MVector v a
=> MVector v n s a
-> MVector v k s a
Expand Down Expand Up @@ -354,13 +352,13 @@ unsafeModify :: forall v n m a. (PrimMonad m, VGM.MVector v a)
unsafeModify (MVector v) = VGM.unsafeModify v
{-# inline unsafeModify #-}

-- | /O(1)/ Swap the elements at a given type-safe position using 'Finite's.
-- | /O(1)/ Swap the elements at given type-safe positions using 'Finite's.
swap :: forall v n m a. (PrimMonad m, VGM.MVector v a)
=> MVector v n (PrimState m) a -> Finite n -> Finite n -> m ()
swap (MVector v) (Finite i) (Finite j) = VGM.unsafeSwap v (fromIntegral i) (fromIntegral j)
{-# inline swap #-}

-- | /O(1)/ Swap the elements at a given 'Int' position without bounds
-- | /O(1)/ Swap the elements at given 'Int' positions without bounds
-- checking.
unsafeSwap :: forall v n m a. (PrimMonad m, VGM.MVector v a)
=> MVector v n (PrimState m) a -> Int -> Int -> m ()
Expand Down Expand Up @@ -391,7 +389,7 @@ unsafeExchange (MVector v) = VGM.unsafeExchange v
#if MIN_VERSION_vector(0,12,0)
-- * Modifying vectors

-- | Compute the next (lexicographically) permutation of a given vector
-- | Compute the next permutation (in lexicographic order) of a given vector
-- in-place. Returns 'False' when the input is the last permutation.
nextPermutation :: forall v n e m. (Ord e, PrimMonad m, VGM.MVector v e)
=> MVector v n (PrimState m) e -> m Bool
Expand Down
13 changes: 7 additions & 6 deletions src/Data/Vector/Generic/Mutable/Sized/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

module Data.Vector.Generic.Mutable.Sized.Internal
( MVector(..)
) where
)
where

import GHC.Generics (Generic)
import GHC.TypeLits
import Control.DeepSeq (NFData)
import Data.Data
import Foreign.Storable
import GHC.Generics ( Generic )
import GHC.TypeLits
import Control.DeepSeq ( NFData )
import Data.Data
import Foreign.Storable

-- | A wrapper to tag mutable vectors with a type level length.
--
Expand Down
Loading

0 comments on commit 1de05be

Please sign in to comment.