hw-bits 0.0.0.3 → 0.0.0.5
raw patch · 26 files changed
+223/−686 lines, 26 filesdep +hw-primdep ~basenew-uploader
Dependencies added: hw-prim
Dependency ranges changed: base
Files
- bench/Main.hs +7/−1
- hw-bits.cabal +6/−11
- src/HaskellWorks/Data/Bits/BitLength.hs +1/−0
- src/HaskellWorks/Data/Bits/BitParse.hs +12/−8
- src/HaskellWorks/Data/Bits/BitRead.hs +2/−0
- src/HaskellWorks/Data/Bits/BitShow.hs +12/−9
- src/HaskellWorks/Data/Bits/BitShown.hs +2/−0
- src/HaskellWorks/Data/Bits/BitWise.hs +58/−46
- src/HaskellWorks/Data/Bits/ElemFixedBitSize.hs +9/−1
- src/HaskellWorks/Data/Bits/FixedBitSize.hs +5/−0
- src/HaskellWorks/Data/Bits/PopCount.hs +1/−0
- src/HaskellWorks/Data/Bits/PopCount/PopCount0.hs +45/−50
- src/HaskellWorks/Data/Bits/PopCount/PopCount1.hs +1/−0
- src/HaskellWorks/Data/Bits/Types/Broadword.hs +8/−1
- src/HaskellWorks/Data/Bits/Types/Builtin.hs +8/−1
- src/HaskellWorks/Data/Bits/Word.hs +40/−0
- src/HaskellWorks/Data/ByteString.hs +0/−11
- src/HaskellWorks/Data/FromByteString.hs +0/−8
- src/HaskellWorks/Data/FromForeignRegion.hs +0/−7
- src/HaskellWorks/Data/Positioning.hs +0/−34
- src/HaskellWorks/Data/Search.hs +0/−12
- src/HaskellWorks/Data/Vector/BoxedVectorLike.hs +0/−56
- src/HaskellWorks/Data/Vector/StorableVectorLike.hs +0/−56
- src/HaskellWorks/Data/Vector/VectorLike.hs +0/−329
- src/HaskellWorks/Data/Word.hs +0/−40
- test/HaskellWorks/Data/Bits/BitReadSpec.hs +6/−5
bench/Main.hs view
@@ -3,6 +3,7 @@ import Criterion.Main import qualified Data.Vector.Storable as DVS import Data.Word+import HaskellWorks.Data.Bits.PopCount.PopCount0 import HaskellWorks.Data.Bits.PopCount.PopCount1 import HaskellWorks.Data.Bits.Types.Broadword import HaskellWorks.Data.Bits.Types.Builtin@@ -13,7 +14,12 @@ benchPopCount1 :: [Benchmark] benchPopCount1 =- [ env (setupEnvVector 1000000) $ \bv -> bgroup "PopCount1"+ [ env (setupEnvVector 1000000) $ \bv -> bgroup "PopCount0"+ [ bench "Broadword" (nf (map (\n -> getCount (popCount0 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector (Broadword Word64)))))) [0, 1000..100000])+ , bench "Builtin" (nf (map (\n -> getCount (popCount0 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector (Builtin Word64)))))) [0, 1000..100000])+ , bench "Default" (nf (map (\n -> getCount (popCount0 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector Word64 ))))) [0, 1000..100000])+ ]+ , env (setupEnvVector 1000000) $ \bv -> bgroup "PopCount1" [ bench "Broadword" (nf (map (\n -> getCount (popCount1 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector (Broadword Word64)))))) [0, 1000..100000]) , bench "Builtin" (nf (map (\n -> getCount (popCount1 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector (Builtin Word64)))))) [0, 1000..100000]) , bench "Default" (nf (map (\n -> getCount (popCount1 (DVS.take n (DVS.unsafeCast bv :: DVS.Vector Word64 ))))) [0, 1000..100000])
hw-bits.cabal view
@@ -1,5 +1,5 @@ name: hw-bits-version: 0.0.0.3+version: 0.0.0.5 synopsis: Conduits for tokenizing streams. description: Please see README.md homepage: http://github.com/haskell-works/hw-bits#readme@@ -8,7 +8,8 @@ author: John Ky maintainer: newhoggy@gmail.com copyright: 2016 John Ky-category: Data, Conduit+category: Data, Bit+stability: Experimental build-type: Simple extra-source-files: README.md cabal-version: >= 1.10@@ -44,15 +45,7 @@ , HaskellWorks.Data.Bits.PopCount.PopCount1 , HaskellWorks.Data.Bits.Types.Broadword , HaskellWorks.Data.Bits.Types.Builtin- , HaskellWorks.Data.ByteString- , HaskellWorks.Data.FromByteString- , HaskellWorks.Data.FromForeignRegion- , HaskellWorks.Data.Positioning- , HaskellWorks.Data.Search- , HaskellWorks.Data.Vector.BoxedVectorLike- , HaskellWorks.Data.Vector.StorableVectorLike- , HaskellWorks.Data.Vector.VectorLike- , HaskellWorks.Data.Word+ , HaskellWorks.Data.Bits.Word build-depends: base >= 4.7 && < 5 , array , attoparsec@@ -60,6 +53,7 @@ , conduit , deepseq , ghc-prim+ , hw-prim , lens , mmap , mono-traversable@@ -111,6 +105,7 @@ , conduit , criterion , hw-bits+ , hw-prim , mmap , resourcet , vector
src/HaskellWorks/Data/Bits/BitLength.hs view
@@ -21,6 +21,7 @@ import HaskellWorks.Data.Vector.VectorLike import Prelude as P +-- | Number of bits in a value including ones and zeros. class BitLength v where bitLength :: v -> Count
src/HaskellWorks/Data/Bits/BitParse.hs view
@@ -14,12 +14,16 @@ import qualified Data.Vector as DV import qualified Data.Vector.Storable as DVS import Data.Word+import GHC.Exts import HaskellWorks.Data.Bits.BitLength import HaskellWorks.Data.Bits.BitWise import Text.ParserCombinators.Parsec +-- | Parsers for bit strings class BitParse a where+ -- | Version of bit string parser that can consume no inputs bitParse0 :: Parser a+ -- | Version of bit string parser that must consume at least one input bitParse1 :: Parser a p0 :: Parser Bool@@ -96,32 +100,32 @@ instance BitParse (DV.Vector Word8) where bitParse0 = option DV.empty bitParse1- bitParse1 = DV.fromList `fmap` bitParse0+ bitParse1 = fromList `fmap` bitParse0 instance BitParse (DV.Vector Word16) where bitParse0 = option DV.empty bitParse1- bitParse1 = DV.fromList `fmap` bitParse0+ bitParse1 = fromList `fmap` bitParse0 instance BitParse (DV.Vector Word32) where bitParse0 = option DV.empty bitParse1- bitParse1 = DV.fromList `fmap` bitParse0+ bitParse1 = fromList `fmap` bitParse0 instance BitParse (DV.Vector Word64) where bitParse0 = option DV.empty bitParse1- bitParse1 = DV.fromList `fmap` bitParse0+ bitParse1 = fromList `fmap` bitParse0 instance BitParse (DVS.Vector Word8) where bitParse0 = option DVS.empty bitParse1- bitParse1 = DVS.fromList `fmap` bitParse0+ bitParse1 = fromList `fmap` bitParse0 instance BitParse (DVS.Vector Word16) where bitParse0 = option DVS.empty bitParse1- bitParse1 = DVS.fromList `fmap` bitParse0+ bitParse1 = fromList `fmap` bitParse0 instance BitParse (DVS.Vector Word32) where bitParse0 = option DVS.empty bitParse1- bitParse1 = DVS.fromList `fmap` bitParse0+ bitParse1 = fromList `fmap` bitParse0 instance BitParse (DVS.Vector Word64) where bitParse0 = option DVS.empty bitParse1- bitParse1 = DVS.fromList `fmap` bitParse0+ bitParse1 = fromList `fmap` bitParse0
src/HaskellWorks/Data/Bits/BitRead.hs view
@@ -12,7 +12,9 @@ import HaskellWorks.Data.Bits.BitParse import Text.ParserCombinators.Parsec +-- | Bit string reader that produces a value of a type class BitRead a where+ -- | Read a bit string into a value bitRead :: String -> Maybe a bitRead' :: BitParse a => String -> Maybe a
src/HaskellWorks/Data/Bits/BitShow.hs view
@@ -15,10 +15,13 @@ import qualified Data.Vector as DV import qualified Data.Vector.Storable as DVS import Data.Word+import GHC.Exts import HaskellWorks.Data.Bits.BitWise-import HaskellWorks.Data.Word+import HaskellWorks.Data.Bits.Word +-- | Shower of a value as a bit string class BitShow a where+ -- | Show a value as a bit string bitShows :: a -> String -> String instance BitShow Bool where@@ -77,28 +80,28 @@ bitShows (w:ws) = bitShows w . (' ':) . bitShows ws instance BitShow (DV.Vector Word8) where- bitShows = bitShows . DV.toList+ bitShows = bitShows . toList instance BitShow (DV.Vector Word16) where- bitShows = bitShows . DV.toList+ bitShows = bitShows . toList instance BitShow (DV.Vector Word32) where- bitShows = bitShows . DV.toList+ bitShows = bitShows . toList instance BitShow (DV.Vector Word64) where- bitShows = bitShows . DV.toList+ bitShows = bitShows . toList instance BitShow (DVS.Vector Word8) where- bitShows = bitShows . DVS.toList+ bitShows = bitShows . toList instance BitShow (DVS.Vector Word16) where- bitShows = bitShows . DVS.toList+ bitShows = bitShows . toList instance BitShow (DVS.Vector Word32) where- bitShows = bitShows . DVS.toList+ bitShows = bitShows . toList instance BitShow (DVS.Vector Word64) where- bitShows = bitShows . DVS.toList+ bitShows = bitShows . toList bitShow :: BitShow a => a -> String bitShow a = bitShows a ""
src/HaskellWorks/Data/Bits/BitShown.hs view
@@ -17,6 +17,7 @@ import HaskellWorks.Data.Bits.BitWise import HaskellWorks.Data.FromByteString +-- | Tag for a value describe the value as being able to be shown as a bit string newtype BitShown a = BitShown a deriving (Eq, BitRead, BitShow) deriving instance Functor BitShown@@ -27,6 +28,7 @@ instance BitShow a => Show (BitShown a) where show a = bitShows a "" +-- | Show the value as a bit string bitShown :: BitShown a -> a bitShown (BitShown a) = a
src/HaskellWorks/Data/Bits/BitWise.hs view
@@ -33,19 +33,31 @@ infixl 6 .^. -- Bitwise XOR. eg. ⊕ infixl 5 .|. -- Bitwise OR. eg. ∨ +-- | Class of values that have shift operations class Shift a where+ -- | Shift left by the specified count (.<.) :: a -> Count -> a+ -- | Shift right by the specified count (.>.) :: a -> Count -> a + -- | Class of values that have bit test operations class TestBit a where+ -- | Test whether the bit ad the given offset is set (.?.) :: a -> Position -> Bool +-- | Class of values that have bit wise logical operations class BitWise a where+ -- | Bit wise AND (.&.) :: a -> a -> a+ -- | Bit wise OR (.|.) :: a -> a -> a+ -- | Bit wise XOR (.^.) :: a -> a -> a+ -- | Bit wise complement comp :: a -> a+ -- | Bit-wise value of the given type with all bits set to zero all0s :: a+ -- | Bit-wise value of the given type with all bits set to one all1s :: a --------------------------------------------------------------------------------@@ -54,160 +66,160 @@ instance TestBit Bool where (.?.) w 0 = w (.?.) _ _ = error "Invalid bit index"- {-# INLINABLE (.?.) #-}+ {-# INLINE (.?.) #-} instance TestBit [Bool] where (.?.) v p = v !! fromIntegral p- {-# INLINABLE (.?.) #-}+ {-# INLINE (.?.) #-} instance TestBit Word8 where (.?.) w n = B.testBit w (fromIntegral (getPosition n))- {-# INLINABLE (.?.) #-}+ {-# INLINE (.?.) #-} instance TestBit Word16 where (.?.) w n = B.testBit w (fromIntegral (getPosition n))- {-# INLINABLE (.?.) #-}+ {-# INLINE (.?.) #-} instance TestBit Word32 where (.?.) w n = B.testBit w (fromIntegral (getPosition n))- {-# INLINABLE (.?.) #-}+ {-# INLINE (.?.) #-} instance TestBit Word64 where (.?.) w n = B.testBit w (fromIntegral (getPosition n))- {-# INLINABLE (.?.) #-}+ {-# INLINE (.?.) #-} instance TestBit (DV.Vector Word8) where (.?.) v n = let (q, r) = n `quotRem` elemBitEnd v in (v !!! q) .?. r- {-# INLINABLE (.?.) #-}+ {-# INLINE (.?.) #-} instance TestBit (DV.Vector Word16) where (.?.) v n = let (q, r) = n `quotRem` elemBitEnd v in (v !!! q) .?. r- {-# INLINABLE (.?.) #-}+ {-# INLINE (.?.) #-} instance TestBit (DV.Vector Word32) where (.?.) v n = let (q, r) = n `quotRem` elemBitEnd v in (v !!! q) .?. r- {-# INLINABLE (.?.) #-}+ {-# INLINE (.?.) #-} instance TestBit (DV.Vector Word64) where (.?.) v n = let (q, r) = n `quotRem` elemBitEnd v in (v !!! q) .?. r- {-# INLINABLE (.?.) #-}+ {-# INLINE (.?.) #-} instance TestBit (DVS.Vector Word8) where (.?.) v n = let (q, r) = n `quotRem` elemBitEnd v in (v !!! q) .?. r- {-# INLINABLE (.?.) #-}+ {-# INLINE (.?.) #-} instance TestBit (DVS.Vector Word16) where (.?.) v n = let (q, r) = n `quotRem` elemBitEnd v in (v !!! q) .?. r- {-# INLINABLE (.?.) #-}+ {-# INLINE (.?.) #-} instance TestBit (DVS.Vector Word32) where (.?.) v n = let (q, r) = n `quotRem` elemBitEnd v in (v !!! q) .?. r- {-# INLINABLE (.?.) #-}+ {-# INLINE (.?.) #-} instance TestBit (DVS.Vector Word64) where (.?.) v n = let (q, r) = n `quotRem` elemBitEnd v in (v !!! q) .?. r- {-# INLINABLE (.?.) #-}+ {-# INLINE (.?.) #-} instance BitWise Word8 where (.&.) = (B..&.)- {-# INLINABLE (.&.) #-}+ {-# INLINE (.&.) #-} (.|.) = (B..|.)- {-# INLINABLE (.|.) #-}+ {-# INLINE (.|.) #-} (.^.) = B.xor- {-# INLINABLE (.^.) #-}+ {-# INLINE (.^.) #-} comp = B.complement- {-# INLINABLE comp #-}+ {-# INLINE comp #-} all0s = 0- {-# INLINABLE all0s #-}+ {-# INLINE all0s #-} all1s = 0- {-# INLINABLE all1s #-}+ {-# INLINE all1s #-} instance BitWise Word16 where (.&.) = (B..&.)- {-# INLINABLE (.&.) #-}+ {-# INLINE (.&.) #-} (.|.) = (B..|.)- {-# INLINABLE (.|.) #-}+ {-# INLINE (.|.) #-} (.^.) = B.xor- {-# INLINABLE (.^.) #-}+ {-# INLINE (.^.) #-} comp = B.complement- {-# INLINABLE comp #-}+ {-# INLINE comp #-} all0s = 0- {-# INLINABLE all0s #-}+ {-# INLINE all0s #-} all1s = 0- {-# INLINABLE all1s #-}+ {-# INLINE all1s #-} instance BitWise Word32 where (.&.) = (B..&.)- {-# INLINABLE (.&.) #-}+ {-# INLINE (.&.) #-} (.|.) = (B..|.)- {-# INLINABLE (.|.) #-}+ {-# INLINE (.|.) #-} (.^.) = B.xor- {-# INLINABLE (.^.) #-}+ {-# INLINE (.^.) #-} comp = B.complement- {-# INLINABLE comp #-}+ {-# INLINE comp #-} all0s = 0- {-# INLINABLE all0s #-}+ {-# INLINE all0s #-} all1s = 0- {-# INLINABLE all1s #-}+ {-# INLINE all1s #-} instance BitWise Word64 where (.&.) = (B..&.)- {-# INLINABLE (.&.) #-}+ {-# INLINE (.&.) #-} (.|.) = (B..|.)- {-# INLINABLE (.|.) #-}+ {-# INLINE (.|.) #-} (.^.) = B.xor- {-# INLINABLE (.^.) #-}+ {-# INLINE (.^.) #-} comp = B.complement- {-# INLINABLE comp #-}+ {-# INLINE comp #-} all0s = 0- {-# INLINABLE all0s #-}+ {-# INLINE all0s #-} all1s = 0- {-# INLINABLE all1s #-}+ {-# INLINE all1s #-} instance Shift Word8 where (.<.) w n = B.shiftL w (fromIntegral n)- {-# INLINABLE (.<.) #-}+ {-# INLINE (.<.) #-} (.>.) w n = B.shiftR w (fromIntegral n)- {-# INLINABLE (.>.) #-}+ {-# INLINE (.>.) #-} instance Shift Word16 where (.<.) w n = B.shiftL w (fromIntegral n)- {-# INLINABLE (.<.) #-}+ {-# INLINE (.<.) #-} (.>.) w n = B.shiftR w (fromIntegral n)- {-# INLINABLE (.>.) #-}+ {-# INLINE (.>.) #-} instance Shift Word32 where (.<.) w n = B.shiftL w (fromIntegral n)- {-# INLINABLE (.<.) #-}+ {-# INLINE (.<.) #-} (.>.) w n = B.shiftR w (fromIntegral n)- {-# INLINABLE (.>.) #-}+ {-# INLINE (.>.) #-} instance Shift Word64 where (.<.) w n = B.shiftL w (fromIntegral n)- {-# INLINABLE (.<.) #-}+ {-# INLINE (.<.) #-} (.>.) w n = B.shiftR w (fromIntegral n)- {-# INLINABLE (.>.) #-}+ {-# INLINE (.>.) #-}
src/HaskellWorks/Data/Bits/ElemFixedBitSize.hs view
@@ -16,8 +16,17 @@ import Data.Word import HaskellWorks.Data.Positioning +-- | Class of values that have elements of a fixed bit size+--+-- >>> elemFixedBitSize (Vector Word8)+-- 8 class ElemFixedBitSize v where+ -- | The element type of the elemnet type Elem v+ -- | Get the bit size of an element for a given composite bit-string type.+ --+ -- >>> elemFixedBitSize (Vector Word8)+ -- 8 elemFixedBitSize :: v -> Count instance ElemFixedBitSize [Bool] where@@ -79,4 +88,3 @@ instance ElemFixedBitSize (DVS.Vector Word64) where type Elem (DVS.Vector Word64) = Word64 elemFixedBitSize _ = 64-
src/HaskellWorks/Data/Bits/FixedBitSize.hs view
@@ -11,7 +11,12 @@ import Data.Word import HaskellWorks.Data.Positioning +-- | Class of values that have a fix bit size class FixedBitSize a where+ -- | Get the bit size of a value of given type.+ --+ -- >>> fixedBitSize Word8+ -- 8 fixedBitSize :: a -> Count instance FixedBitSize Bool where
src/HaskellWorks/Data/Bits/PopCount.hs view
@@ -15,5 +15,6 @@ import HaskellWorks.Data.Bits.PopCount.PopCount1 as X import HaskellWorks.Data.Positioning +{-# DEPRECATED #-} class PopCount v e where popCount :: e -> v -> Count
src/HaskellWorks/Data/Bits/PopCount/PopCount0.hs view
@@ -14,83 +14,78 @@ import qualified Data.Vector as DV import qualified Data.Vector.Storable as DVS import Data.Word-import HaskellWorks.Data.Bits.BitLength+import HaskellWorks.Data.Bits.BitWise import HaskellWorks.Data.Bits.PopCount.PopCount1+import HaskellWorks.Data.Bits.Types.Broadword+import HaskellWorks.Data.Bits.Types.Builtin import HaskellWorks.Data.Positioning import Prelude as P +-- | The number of zero bits in the value. class PopCount0 v where popCount0 :: v -> Count instance PopCount0 Bool where popCount0 True = 0 popCount0 False = 1- {-# INLINABLE popCount0 #-}+ {-# INLINE popCount0 #-} instance PopCount0 Word8 where- popCount0 x0 = bitLength x0 - popCount1 x0- {-# INLINABLE popCount0 #-}+ popCount0 = popCount1 . comp+ {-# INLINE popCount0 #-} instance PopCount0 Word16 where- popCount0 x0 = bitLength x0 - popCount1 x0- {-# INLINABLE popCount0 #-}+ popCount0 = popCount1 . comp+ {-# INLINE popCount0 #-} instance PopCount0 Word32 where- popCount0 x0 = bitLength x0 - popCount1 x0- {-# INLINABLE popCount0 #-}+ popCount0 = popCount1 . comp+ {-# INLINE popCount0 #-} instance PopCount0 Word64 where- popCount0 x0 = bitLength x0 - popCount1 x0- {-# INLINABLE popCount0 #-}--instance PopCount0 [Bool] where- popCount0 = P.sum . fmap popCount0- {-# INLINABLE popCount0 #-}--instance PopCount0 [Word8] where- popCount0 = P.sum . fmap popCount0- {-# INLINABLE popCount0 #-}+ popCount0 = popCount1 . comp+ {-# INLINE popCount0 #-} -instance PopCount0 [Word16] where- popCount0 = P.sum . fmap popCount0- {-# INLINABLE popCount0 #-}+instance PopCount0 (Broadword Word8) where+ popCount0 = popCount1 . comp+ {-# INLINE popCount0 #-} -instance PopCount0 [Word32] where- popCount0 = P.sum . fmap popCount0- {-# INLINABLE popCount0 #-}+instance PopCount0 (Broadword Word16) where+ popCount0 = popCount1 . comp+ {-# INLINE popCount0 #-} -instance PopCount0 [Word64] where- popCount0 = P.sum . fmap popCount0- {-# INLINABLE popCount0 #-}+instance PopCount0 (Broadword Word32) where+ popCount0 = popCount1 . comp+ {-# INLINE popCount0 #-} -instance PopCount0 (DV.Vector Word8) where- popCount0 = DV.foldl (\c -> (c +) . popCount0) 0- {-# INLINABLE popCount0 #-}+instance PopCount0 (Broadword Word64) where+ popCount0 = popCount1 . comp+ {-# INLINE popCount0 #-} -instance PopCount0 (DV.Vector Word16) where- popCount0 = DV.foldl (\c -> (c +) . popCount0) 0- {-# INLINABLE popCount0 #-}+instance PopCount0 (Builtin Word8) where+ popCount0 = popCount1 . comp+ {-# INLINE popCount0 #-} -instance PopCount0 (DV.Vector Word32) where- popCount0 = DV.foldl (\c -> (c +) . popCount0) 0- {-# INLINABLE popCount0 #-}+instance PopCount0 (Builtin Word16) where+ popCount0 = popCount1 . comp+ {-# INLINE popCount0 #-} -instance PopCount0 (DV.Vector Word64) where- popCount0 = DV.foldl (\c -> (c +) . popCount0) 0- {-# INLINABLE popCount0 #-}+instance PopCount0 (Builtin Word32) where+ popCount0 = popCount1 . comp+ {-# INLINE popCount0 #-} -instance PopCount0 (DVS.Vector Word8) where- popCount0 = DVS.foldl (\c -> (c +) . popCount0) 0- {-# INLINABLE popCount0 #-}+instance PopCount0 (Builtin Word64) where+ popCount0 = popCount1 . comp+ {-# INLINE popCount0 #-} -instance PopCount0 (DVS.Vector Word16) where- popCount0 = DVS.foldl (\c -> (c +) . popCount0) 0- {-# INLINABLE popCount0 #-}+instance PopCount0 a => PopCount0 [a] where+ popCount0 = P.sum . fmap popCount0+ {-# INLINE popCount0 #-} -instance PopCount0 (DVS.Vector Word32) where- popCount0 = DVS.foldl (\c -> (c +) . popCount0) 0- {-# INLINABLE popCount0 #-}+instance PopCount0 a => PopCount0 (DV.Vector a) where+ popCount0 = DV.foldl (\c -> (c +) . popCount0) 0+ {-# INLINE popCount0 #-} -instance PopCount0 (DVS.Vector Word64) where+instance (DVS.Storable a, PopCount0 a) => PopCount0 (DVS.Vector a) where popCount0 = DVS.foldl (\c -> (c +) . popCount0) 0- {-# INLINABLE popCount0 #-}+ {-# INLINE popCount0 #-}
src/HaskellWorks/Data/Bits/PopCount/PopCount1.hs view
@@ -25,6 +25,7 @@ fastWord = Builtin {-# INLINE fastWord #-} +-- | The number of one bits in the value. class PopCount1 v where popCount1 :: v -> Count
src/HaskellWorks/Data/Bits/Types/Broadword.hs view
@@ -1,7 +1,14 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} +-- |+-- Copyright: 2016 John Ky+-- License: MIT+--+-- Succinct operations. module HaskellWorks.Data.Bits.Types.Broadword where import Data.Vector.Storable+import HaskellWorks.Data.Bits.BitWise -newtype Broadword a = Broadword a deriving (Eq, Show, Storable)+-- | Type wrapper to prefer broadword operations+newtype Broadword a = Broadword a deriving (BitWise, Eq, Show, Storable)
src/HaskellWorks/Data/Bits/Types/Builtin.hs view
@@ -1,7 +1,14 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} +-- |+-- Copyright: 2016 John Ky+-- License: MIT+--+-- Succinct operations. module HaskellWorks.Data.Bits.Types.Builtin where import Data.Vector.Storable+import HaskellWorks.Data.Bits.BitWise -newtype Builtin a = Builtin a deriving (Eq, Show, Storable)+-- | Type wrapper to prefer builting operations+newtype Builtin a = Builtin a deriving (BitWise, Eq, Show, Storable)
+ src/HaskellWorks/Data/Bits/Word.hs view
@@ -0,0 +1,40 @@+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE TypeFamilies #-}++module HaskellWorks.Data.Bits.Word where++import Data.Word+import HaskellWorks.Data.Bits.BitLength+import HaskellWorks.Data.Bits.BitWise++class WordConcat a where+ type DoubleWords a+ leConcat :: a -> a -> DoubleWords a++class WordSplit a where+ type HalfWords a+ leSplit :: a -> (HalfWords a, HalfWords a)++instance WordConcat Word8 where+ type DoubleWords Word8 = Word16+ leConcat a b = (fromIntegral b .<. bitLength a) .|. fromIntegral a++instance WordConcat Word16 where+ type DoubleWords Word16 = Word32+ leConcat a b = (fromIntegral b .<. bitLength a) .|. fromIntegral a++instance WordConcat Word32 where+ type DoubleWords Word32 = Word64+ leConcat a b = (fromIntegral b .<. bitLength a) .|. fromIntegral a++instance WordSplit Word64 where+ type HalfWords Word64 = Word32+ leSplit a = (fromIntegral a, fromIntegral (a .>. 32))++instance WordSplit Word32 where+ type HalfWords Word32 = Word16+ leSplit a = (fromIntegral a, fromIntegral (a .>. 16))++instance WordSplit Word16 where+ type HalfWords Word16 = Word8+ leSplit a = (fromIntegral a, fromIntegral (a .>. 8))
− src/HaskellWorks/Data/ByteString.hs
@@ -1,11 +0,0 @@-module HaskellWorks.Data.ByteString- ( chunkedBy- ) where--import qualified Data.ByteString as BS--chunkedBy :: Int -> BS.ByteString -> [BS.ByteString]-chunkedBy n bs = if BS.length bs == 0- then []- else case BS.splitAt n bs of- (as, zs) -> as : chunkedBy n zs
− src/HaskellWorks/Data/FromByteString.hs
@@ -1,8 +0,0 @@-module HaskellWorks.Data.FromByteString- ( FromByteString(..)- ) where--import Data.ByteString.Internal--class FromByteString a where- fromByteString :: ByteString -> a
− src/HaskellWorks/Data/FromForeignRegion.hs
@@ -1,7 +0,0 @@-module HaskellWorks.Data.FromForeignRegion where--import Data.Word-import Foreign.ForeignPtr--class FromForeignRegion a where- fromForeignRegion :: (ForeignPtr Word8, Int, Int) -> a
− src/HaskellWorks/Data/Positioning.hs
@@ -1,34 +0,0 @@-{-# LANGUAGE GeneralizedNewtypeDeriving #-}--module HaskellWorks.Data.Positioning- ( Count(..)- , Position(..)- , lastPositionOf- , toCount- , toPosition- ) where--import Data.Int-import Data.Word-import System.Random--newtype Count = Count { getCount :: Word64 }- deriving (Eq, Num, Ord, Enum, Integral, Real, Random)--instance Show Count where- show (Count w64) = show w64--newtype Position = Position { getPosition :: Int64 }- deriving (Eq, Num, Ord, Enum, Real, Integral)--instance Show Position where- show (Position n) = show n--toPosition :: Count -> Position-toPosition (Count n) = Position (fromIntegral n)--toCount :: Position -> Count-toCount (Position n) = Count (fromIntegral n)--lastPositionOf :: Count -> Position-lastPositionOf (Count c) = Position (fromIntegral c - 1)
− src/HaskellWorks/Data/Search.hs
@@ -1,12 +0,0 @@-module HaskellWorks.Data.Search- ( binarySearch- ) where--binarySearch :: (Ord a, Integral n) => a -> (n -> a) -> n -> n -> n-binarySearch w f p q = if p + 1 >= q- then p- else let m = p + q `div` 2 in- if w <= f m- then binarySearch w f p m- else binarySearch w f m q-{-# INLINABLE binarySearch #-}
− src/HaskellWorks/Data/Vector/BoxedVectorLike.hs
@@ -1,56 +0,0 @@-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}--module HaskellWorks.Data.Vector.BoxedVectorLike- ( BoxedVectorLike(..)- ) where--import qualified Data.Vector as DV-import Data.Word-import Foreign.Storable--class BoxedVectorLike v e where- bImap :: (Int -> a -> b) -> v a -> v b- bMap :: (a -> b) -> v a -> v b- bUnfoldr :: (Storable a) => (b -> Maybe (a, b)) -> b -> v a- bUnfoldrN :: (Storable a) => Int -> (b -> Maybe (a, b)) -> b -> v a--instance BoxedVectorLike DV.Vector Word8 where- bImap = DV.imap- bMap = DV.map- bUnfoldr = DV.unfoldr- bUnfoldrN = DV.unfoldrN- {-# INLINABLE bImap #-}- {-# INLINABLE bMap #-}- {-# INLINABLE bUnfoldr #-}- {-# INLINABLE bUnfoldrN #-}--instance BoxedVectorLike DV.Vector Word16 where- bImap = DV.imap- bMap = DV.map- bUnfoldr = DV.unfoldr- bUnfoldrN = DV.unfoldrN- {-# INLINABLE bImap #-}- {-# INLINABLE bMap #-}- {-# INLINABLE bUnfoldr #-}- {-# INLINABLE bUnfoldrN #-}--instance BoxedVectorLike DV.Vector Word32 where- bImap = DV.imap- bMap = DV.map- bUnfoldr = DV.unfoldr- bUnfoldrN = DV.unfoldrN- {-# INLINABLE bImap #-}- {-# INLINABLE bMap #-}- {-# INLINABLE bUnfoldr #-}- {-# INLINABLE bUnfoldrN #-}--instance BoxedVectorLike DV.Vector Word64 where- bImap = DV.imap- bMap = DV.map- bUnfoldr = DV.unfoldr- bUnfoldrN = DV.unfoldrN- {-# INLINABLE bImap #-}- {-# INLINABLE bMap #-}- {-# INLINABLE bUnfoldr #-}- {-# INLINABLE bUnfoldrN #-}
− src/HaskellWorks/Data/Vector/StorableVectorLike.hs
@@ -1,56 +0,0 @@-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}--module HaskellWorks.Data.Vector.StorableVectorLike- ( StorableVectorLike(..)- ) where--import qualified Data.Vector.Storable as DVS-import Data.Word-import Foreign.Storable--class StorableVectorLike v e where- sImap :: (Storable a, Storable b) => (Int -> a -> b) -> v a -> v b- sMap :: (Storable a, Storable b) => (a -> b) -> v a -> v b- sUnfoldr :: (Storable a) => (b -> Maybe (a, b)) -> b -> v a- sUnfoldrN :: (Storable a) => Int -> (b -> Maybe (a, b)) -> b -> v a--instance StorableVectorLike DVS.Vector Word8 where- sImap = DVS.imap- sMap = DVS.map- sUnfoldr = DVS.unfoldr- sUnfoldrN = DVS.unfoldrN- {-# INLINABLE sImap #-}- {-# INLINABLE sMap #-}- {-# INLINABLE sUnfoldr #-}- {-# INLINABLE sUnfoldrN #-}--instance StorableVectorLike DVS.Vector Word16 where- sImap = DVS.imap- sMap = DVS.map- sUnfoldr = DVS.unfoldr- sUnfoldrN = DVS.unfoldrN- {-# INLINABLE sImap #-}- {-# INLINABLE sMap #-}- {-# INLINABLE sUnfoldr #-}- {-# INLINABLE sUnfoldrN #-}--instance StorableVectorLike DVS.Vector Word32 where- sImap = DVS.imap- sMap = DVS.map- sUnfoldr = DVS.unfoldr- sUnfoldrN = DVS.unfoldrN- {-# INLINABLE sImap #-}- {-# INLINABLE sMap #-}- {-# INLINABLE sUnfoldr #-}- {-# INLINABLE sUnfoldrN #-}--instance StorableVectorLike DVS.Vector Word64 where- sImap = DVS.imap- sMap = DVS.map- sUnfoldr = DVS.unfoldr- sUnfoldrN = DVS.unfoldrN- {-# INLINABLE sImap #-}- {-# INLINABLE sMap #-}- {-# INLINABLE sUnfoldr #-}- {-# INLINABLE sUnfoldrN #-}
− src/HaskellWorks/Data/Vector/VectorLike.hs
@@ -1,329 +0,0 @@-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE TypeFamilies #-}--module HaskellWorks.Data.Vector.VectorLike- ( VectorLike(..)- ) where--import qualified Data.ByteString as BS-import qualified Data.Vector as DV-import qualified Data.Vector.Storable as DVS-import Data.Word-import HaskellWorks.Data.Positioning--class VectorLike v where- type Elem v- vToList :: v -> [Elem v]- vFromList :: [Elem v] -> v- (!!!) :: v -> Position -> Elem v- vConcat :: [v] -> v- vEmpty :: v- vFilter :: (Elem v -> Bool) -> v -> v- vGenerate :: Int -> (Int -> Elem v) -> v- vLength :: v -> Count- vSnoc :: v -> Elem v -> v- vDrop :: Count -> v -> v- vTake :: Count -> v -> v- vIndex :: v -> Position -> Elem v- vSlice :: Position -> Position -> v -> v--instance VectorLike String where- type Elem String = Char- vToList = id- vFromList = id- (!!!) v (Position i) = v !! fromIntegral i- vConcat = concat- vEmpty = ""- vFilter = filter- vGenerate n f = f `fmap` [0 .. (n - 1)]- vLength = Count . fromIntegral . length- vSnoc v c = v ++ [c]- vDrop = drop . fromIntegral- vTake = take . fromIntegral- vIndex v (Position i) = v !! fromIntegral i- vSlice (Position i) (Position j) = take (fromIntegral j) . drop (fromIntegral i)- {-# INLINABLE vToList #-}- {-# INLINABLE vFromList #-}- {-# INLINABLE (!!!) #-}- {-# INLINABLE vConcat #-}- {-# INLINABLE vEmpty #-}- {-# INLINABLE vFilter #-}- {-# INLINABLE vGenerate #-}- {-# INLINABLE vLength #-}- {-# INLINABLE vSnoc #-}- {-# INLINABLE vDrop #-}- {-# INLINABLE vTake #-}- {-# INLINABLE vIndex #-}- {-# INLINABLE vSlice #-}--instance VectorLike BS.ByteString where- type Elem BS.ByteString = Word8-- vToList = BS.unpack- vFromList = BS.pack- (!!!) v (Position i) = v `BS.index` fromIntegral i- vConcat = BS.concat- vEmpty = BS.empty- vFilter = BS.filter- vGenerate n f = fst (BS.unfoldrN n go 0)- where go i = if i /= n then Just (f i, i + 1) else Nothing- vLength = Count . fromIntegral . BS.length- vSnoc = BS.snoc- vDrop = BS.drop . fromIntegral- vTake = BS.take . fromIntegral- vIndex v (Position i) = BS.index v (fromIntegral i)- vSlice (Position i) (Position j) = BS.take (fromIntegral j) . BS.drop (fromIntegral i)- {-# INLINABLE vToList #-}- {-# INLINABLE vFromList #-}- {-# INLINABLE (!!!) #-}- {-# INLINABLE vConcat #-}- {-# INLINABLE vEmpty #-}- {-# INLINABLE vFilter #-}- {-# INLINABLE vGenerate #-}- {-# INLINABLE vLength #-}- {-# INLINABLE vSnoc #-}- {-# INLINABLE vDrop #-}- {-# INLINABLE vTake #-}- {-# INLINABLE vIndex #-}- {-# INLINABLE vSlice #-}--instance VectorLike (DV.Vector Word8) where- type Elem (DV.Vector Word8) = Word8-- vToList = DV.toList- vFromList = DV.fromList- (!!!) v (Position i) = v DV.! fromIntegral i- vConcat = DV.concat- vEmpty = DV.empty- vFilter = DV.filter- vGenerate = DV.generate- vLength = Count . fromIntegral . DV.length- vSnoc = DV.snoc- vDrop = DV.drop . fromIntegral- vTake = DV.take . fromIntegral- vIndex v (Position i) = DV.unsafeIndex v (fromIntegral i)- vSlice (Position i) (Position j) = DV.unsafeSlice (fromIntegral i) (fromIntegral j)- {-# INLINABLE vToList #-}- {-# INLINABLE vFromList #-}- {-# INLINABLE (!!!) #-}- {-# INLINABLE vConcat #-}- {-# INLINABLE vEmpty #-}- {-# INLINABLE vFilter #-}- {-# INLINABLE vGenerate #-}- {-# INLINABLE vLength #-}- {-# INLINABLE vSnoc #-}- {-# INLINABLE vDrop #-}- {-# INLINABLE vTake #-}- {-# INLINABLE vIndex #-}- {-# INLINABLE vSlice #-}--instance VectorLike (DV.Vector Word16) where- type Elem (DV.Vector Word16) = Word16-- vToList = DV.toList- vFromList = DV.fromList- (!!!) v (Position i) = v DV.! fromIntegral i- vConcat = DV.concat- vEmpty = DV.empty- vFilter = DV.filter- vGenerate = DV.generate- vLength = Count . fromIntegral . DV.length- vSnoc = DV.snoc- vDrop = DV.drop . fromIntegral- vTake = DV.take . fromIntegral- vIndex v (Position i) = DV.unsafeIndex v (fromIntegral i)- vSlice (Position i) (Position j) = DV.unsafeSlice (fromIntegral i) (fromIntegral j)- {-# INLINABLE vToList #-}- {-# INLINABLE vFromList #-}- {-# INLINABLE (!!!) #-}- {-# INLINABLE vConcat #-}- {-# INLINABLE vEmpty #-}- {-# INLINABLE vFilter #-}- {-# INLINABLE vGenerate #-}- {-# INLINABLE vLength #-}- {-# INLINABLE vSnoc #-}- {-# INLINABLE vDrop #-}- {-# INLINABLE vTake #-}- {-# INLINABLE vIndex #-}- {-# INLINABLE vSlice #-}--instance VectorLike (DV.Vector Word32) where- type Elem (DV.Vector Word32) = Word32-- vToList = DV.toList- vFromList = DV.fromList- (!!!) v (Position i) = v DV.! fromIntegral i- vConcat = DV.concat- vEmpty = DV.empty- vFilter = DV.filter- vGenerate = DV.generate- vLength = Count . fromIntegral . DV.length- vSnoc = DV.snoc- vDrop = DV.drop . fromIntegral- vTake = DV.take . fromIntegral- vIndex v (Position i) = DV.unsafeIndex v (fromIntegral i)- vSlice (Position i) (Position j) = DV.unsafeSlice (fromIntegral i) (fromIntegral j)- {-# INLINABLE vToList #-}- {-# INLINABLE vFromList #-}- {-# INLINABLE (!!!) #-}- {-# INLINABLE vConcat #-}- {-# INLINABLE vEmpty #-}- {-# INLINABLE vFilter #-}- {-# INLINABLE vGenerate #-}- {-# INLINABLE vLength #-}- {-# INLINABLE vSnoc #-}- {-# INLINABLE vDrop #-}- {-# INLINABLE vTake #-}- {-# INLINABLE vIndex #-}- {-# INLINABLE vSlice #-}--instance VectorLike (DV.Vector Word64) where- type Elem (DV.Vector Word64) = Word64-- vToList = DV.toList- vFromList = DV.fromList- (!!!) v (Position i) = v DV.! fromIntegral i- vConcat = DV.concat- vEmpty = DV.empty- vFilter = DV.filter- vGenerate = DV.generate- vLength = Count . fromIntegral . DV.length- vSnoc = DV.snoc- vDrop = DV.drop . fromIntegral- vTake = DV.take . fromIntegral- vIndex v (Position i) = DV.unsafeIndex v (fromIntegral i)- vSlice (Position i) (Position j) = DV.unsafeSlice (fromIntegral i) (fromIntegral j)- {-# INLINABLE vToList #-}- {-# INLINABLE vFromList #-}- {-# INLINABLE (!!!) #-}- {-# INLINABLE vConcat #-}- {-# INLINABLE vEmpty #-}- {-# INLINABLE vFilter #-}- {-# INLINABLE vGenerate #-}- {-# INLINABLE vLength #-}- {-# INLINABLE vSnoc #-}- {-# INLINABLE vDrop #-}- {-# INLINABLE vTake #-}- {-# INLINABLE vIndex #-}- {-# INLINABLE vSlice #-}--instance VectorLike (DVS.Vector Word8) where- type Elem (DVS.Vector Word8) = Word8-- vToList = DVS.toList- vFromList = DVS.fromList- (!!!) v (Position i) = v DVS.! fromIntegral i- vConcat = DVS.concat- vEmpty = DVS.empty- vFilter = DVS.filter- vGenerate = DVS.generate- vLength = Count . fromIntegral . DVS.length- vSnoc = DVS.snoc- vDrop = DVS.drop . fromIntegral- vTake = DVS.take . fromIntegral- vIndex v (Position i) = DVS.unsafeIndex v (fromIntegral i)- vSlice (Position i) (Position j) = DVS.unsafeSlice (fromIntegral i) (fromIntegral j)- {-# INLINABLE vToList #-}- {-# INLINABLE vFromList #-}- {-# INLINABLE (!!!) #-}- {-# INLINABLE vConcat #-}- {-# INLINABLE vEmpty #-}- {-# INLINABLE vFilter #-}- {-# INLINABLE vGenerate #-}- {-# INLINABLE vLength #-}- {-# INLINABLE vSnoc #-}- {-# INLINABLE vDrop #-}- {-# INLINABLE vTake #-}- {-# INLINABLE vIndex #-}- {-# INLINABLE vSlice #-}--instance VectorLike (DVS.Vector Word16) where- type Elem (DVS.Vector Word16) = Word16-- vToList = DVS.toList- vFromList = DVS.fromList- (!!!) v (Position i) = v DVS.! fromIntegral i- vConcat = DVS.concat- vEmpty = DVS.empty- vFilter = DVS.filter- vGenerate = DVS.generate- vLength = Count . fromIntegral . DVS.length- vSnoc = DVS.snoc- vDrop = DVS.drop . fromIntegral- vTake = DVS.take . fromIntegral- vIndex v (Position i) = DVS.unsafeIndex v (fromIntegral i)- vSlice (Position i) (Position j) = DVS.unsafeSlice (fromIntegral i) (fromIntegral j)- {-# INLINABLE vToList #-}- {-# INLINABLE vFromList #-}- {-# INLINABLE (!!!) #-}- {-# INLINABLE vConcat #-}- {-# INLINABLE vEmpty #-}- {-# INLINABLE vFilter #-}- {-# INLINABLE vGenerate #-}- {-# INLINABLE vLength #-}- {-# INLINABLE vSnoc #-}- {-# INLINABLE vDrop #-}- {-# INLINABLE vTake #-}- {-# INLINABLE vIndex #-}- {-# INLINABLE vSlice #-}--instance VectorLike (DVS.Vector Word32) where- type Elem (DVS.Vector Word32) = Word32-- vToList = DVS.toList- vFromList = DVS.fromList- (!!!) v (Position i) = v DVS.! fromIntegral i- vConcat = DVS.concat- vEmpty = DVS.empty- vFilter = DVS.filter- vGenerate = DVS.generate- vLength = Count . fromIntegral . DVS.length- vSnoc = DVS.snoc- vDrop = DVS.drop . fromIntegral- vTake = DVS.take . fromIntegral- vIndex v (Position i) = DVS.unsafeIndex v (fromIntegral i)- vSlice (Position i) (Position j) = DVS.unsafeSlice (fromIntegral i) (fromIntegral j)- {-# INLINABLE vToList #-}- {-# INLINABLE vFromList #-}- {-# INLINABLE (!!!) #-}- {-# INLINABLE vConcat #-}- {-# INLINABLE vEmpty #-}- {-# INLINABLE vFilter #-}- {-# INLINABLE vGenerate #-}- {-# INLINABLE vLength #-}- {-# INLINABLE vSnoc #-}- {-# INLINABLE vDrop #-}- {-# INLINABLE vTake #-}- {-# INLINABLE vIndex #-}- {-# INLINABLE vSlice #-}--instance VectorLike (DVS.Vector Word64) where- type Elem (DVS.Vector Word64) = Word64-- vToList = DVS.toList- vFromList = DVS.fromList- (!!!) v (Position i) = v DVS.! fromIntegral i- vConcat = DVS.concat- vEmpty = DVS.empty- vFilter = DVS.filter- vGenerate = DVS.generate- vLength = Count . fromIntegral . DVS.length- vSnoc = DVS.snoc- vDrop = DVS.drop . fromIntegral- vTake = DVS.take . fromIntegral- vIndex v (Position i) = DVS.unsafeIndex v (fromIntegral i)- vSlice (Position i) (Position j) = DVS.unsafeSlice (fromIntegral i) (fromIntegral j)- {-# INLINABLE vToList #-}- {-# INLINABLE vFromList #-}- {-# INLINABLE (!!!) #-}- {-# INLINABLE vConcat #-}- {-# INLINABLE vEmpty #-}- {-# INLINABLE vFilter #-}- {-# INLINABLE vGenerate #-}- {-# INLINABLE vLength #-}- {-# INLINABLE vSnoc #-}- {-# INLINABLE vDrop #-}- {-# INLINABLE vTake #-}- {-# INLINABLE vIndex #-}- {-# INLINABLE vSlice #-}
− src/HaskellWorks/Data/Word.hs
@@ -1,40 +0,0 @@-{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE TypeFamilies #-}--module HaskellWorks.Data.Word where--import Data.Word-import HaskellWorks.Data.Bits.BitLength-import HaskellWorks.Data.Bits.BitWise--class WordConcat a where- type DoubleWords a- leConcat :: a -> a -> DoubleWords a--class WordSplit a where- type HalfWords a- leSplit :: a -> (HalfWords a, HalfWords a)--instance WordConcat Word8 where- type DoubleWords Word8 = Word16- leConcat a b = (fromIntegral b .<. bitLength a) .|. fromIntegral a--instance WordConcat Word16 where- type DoubleWords Word16 = Word32- leConcat a b = (fromIntegral b .<. bitLength a) .|. fromIntegral a--instance WordConcat Word32 where- type DoubleWords Word32 = Word64- leConcat a b = (fromIntegral b .<. bitLength a) .|. fromIntegral a--instance WordSplit Word64 where- type HalfWords Word64 = Word32- leSplit a = (fromIntegral a, fromIntegral (a .>. 32))--instance WordSplit Word32 where- type HalfWords Word32 = Word16- leSplit a = (fromIntegral a, fromIntegral (a .>. 16))--instance WordSplit Word16 where- type HalfWords Word16 = Word8- leSplit a = (fromIntegral a, fromIntegral (a .>. 8))
test/HaskellWorks/Data/Bits/BitReadSpec.hs view
@@ -1,5 +1,6 @@ {-# OPTIONS_GHC -fno-warn-incomplete-patterns #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE OverloadedLists #-} module HaskellWorks.Data.Bits.BitReadSpec (spec) where @@ -27,16 +28,16 @@ ws `shouldBe` Just [] it "bitRead \"10000000 101\" :: Maybe (DV.Vector Word8)" $ let v = bitRead "10000000 101" :: Maybe (DV.Vector Word8) in- v `shouldBe` Just (DV.fromList [1, 5])+ v `shouldBe` Just [1, 5] it "bitRead \"11100100 10101111 1\" :: Maybe (DV.Vector Word8)" $ let v = bitRead "11100100 10101111 1" :: Maybe (DV.Vector Word8) in- v `shouldBe` Just (DV.fromList [39, 245, 1])+ v `shouldBe` Just [39, 245, 1] it "bitRead \"11100100 10101111 1\" :: Maybe (DV.Vector Word16)" $ let v = bitRead "11100100 10101111 1" :: Maybe (DV.Vector Word16) in- v `shouldBe` Just (DV.fromList [39 + 62720, 1])+ v `shouldBe` Just [39 + 62720, 1] it "bitRead \"\" :: Maybe (DV.Vector Word8)" $ let v = bitRead "" :: Maybe (DV.Vector Word8) in- v `shouldBe` Just (DV.fromList [])+ v `shouldBe` Just [] it "bitShow (8 :: Word8)" $ let bs = bitShow (8 :: Word8) in bs `shouldBe` "00010000"@@ -44,5 +45,5 @@ let bs = bitShow (8 :: Word64) in bs `shouldBe` "00010000 00000000 00000000 00000000 00000000 00000000 00000000 00000000" it "bitShow [0x0102040810204080 :: Word64]" $- let bs = bitShow [0x0102040810204080 :: Word64] in+ let bs = bitShow ([0x0102040810204080] :: [Word64]) in bs `shouldBe` "00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000"