packages feed

cognimeta-utils 0.1.1 → 0.1.2

raw patch · 3 files changed

+12/−9 lines, 3 filesdep ~cognimeta-utilsPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: cognimeta-utils

API changes (from Hackage documentation)

- Cgm.Control.InFunctor: type :<- = RevFun
- Cgm.Control.InFunctor: type :>> a b = StrictlyIncreasing' a b
- Cgm.Control.InFunctor: type :>>= a b = Increasing' a b
- Cgm.Data.Either: type :| a b = Either a b
+ Cgm.Control.InFunctor: type (:<-) = RevFun
+ Cgm.Data.Either: type (:|) a b = Either a b
- Cgm.Control.InFunctor: liftIKtI :: Injection f => f a1 a' -> (a' -> b' -> a') -> a1 -> b' -> a1
+ Cgm.Control.InFunctor: liftIKtI :: Injection f => f a1 a' -> (a' -> a -> a') -> a1 -> a -> a1
- Cgm.Data.Len: ceilDivPower2 :: Bits a => Int -> a -> a
+ Cgm.Data.Len: ceilDivPower2 :: (Num a, Bits a) => Int -> a -> a
- Cgm.Data.Len: coarseRem :: (Bits n, LgMultiple v u) => Len u n -> (Len v n, Len u n)
+ Cgm.Data.Len: coarseRem :: (Bits n, Num n, LgMultiple v u) => Len u n -> (Len v n, Len u n)
- Cgm.Data.Len: coarsenLen :: (Bits n, LgMultiple v u) => Len u n -> Len v n
+ Cgm.Data.Len: coarsenLen :: (Bits n, Num n, LgMultiple v u) => Len u n -> Len v n
- Cgm.Data.Len: roundUpPower2 :: Bits a => Int -> a -> a
+ Cgm.Data.Len: roundUpPower2 :: (Num a, Bits a) => Int -> a -> a
- Cgm.Data.Tagged: at :: Tagged s b -> b
+ Cgm.Data.Tagged: at :: Tagged * s b -> b
- Cgm.Data.Tagged: at2 :: Tagged s1 (Tagged s c) -> c
+ Cgm.Data.Tagged: at2 :: Tagged * s1 (Tagged * s c) -> c
- Cgm.Data.Tagged: at3 :: Tagged s2 (Tagged s1 (Tagged s c)) -> c
+ Cgm.Data.Tagged: at3 :: Tagged * s2 (Tagged * s1 (Tagged * s c)) -> c
- Cgm.Data.Tagged: at4 :: Tagged s3 (Tagged s2 (Tagged s1 (Tagged s c))) -> c
+ Cgm.Data.Tagged: at4 :: Tagged * s3 (Tagged * s2 (Tagged * s1 (Tagged * s c))) -> c
- Cgm.Data.Tagged: tag :: b -> Tagged s b
+ Cgm.Data.Tagged: tag :: b -> Tagged * s b
- Cgm.Data.Tagged: tag2 :: a -> Tagged s (Tagged s1 a)
+ Cgm.Data.Tagged: tag2 :: a -> Tagged * s (Tagged * s1 a)
- Cgm.Data.Tagged: tag3 :: a -> Tagged s (Tagged s1 (Tagged s2 a))
+ Cgm.Data.Tagged: tag3 :: a -> Tagged * s (Tagged * s1 (Tagged * s2 a))
- Cgm.Data.Tagged: tag4 :: a -> Tagged s (Tagged s1 (Tagged s2 (Tagged s3 a)))
+ Cgm.Data.Tagged: tag4 :: a -> Tagged * s (Tagged * s1 (Tagged * s2 (Tagged * s3 a)))
- Cgm.System.Endian: class (Prim w, Bits w) => Endian w
+ Cgm.System.Endian: class (Prim w, Bits w, Num w) => Endian w

Files

cognimeta-utils.cabal view
@@ -1,5 +1,5 @@ Name: cognimeta-utils-version: 0.1.1+version: 0.1.2 cabal-version: >= 1.8 build-type: Simple license: OtherLicense@@ -105,7 +105,7 @@     template-haskell >= 2.7.0.0,     mtl >= 2.1.2,     QuickCheck >=2.4.0.1,-    cognimeta-utils >= 0.1.1,+    cognimeta-utils >= 0.1.2,     transformers >= 0.3.0.0,     bytestring >= 0.9.2.1,     containers >= 0.4.2.1
src/Cgm/Data/Len.hs view
@@ -119,14 +119,16 @@ 
 refineLen :: forall u v n. (Bits n, LgMultiple u v) => Len u n -> Len v n
 refineLen (Len u) = Len $ u `shiftL` getLgMul (lgMul :: LgMul u v)
-coarsenLen :: forall u v n. (Bits n, LgMultiple v u) => Len u n -> Len v n
+coarsenLen :: forall u v n. (Bits n, Num n, LgMultiple v u) => Len u n -> Len v n
 coarsenLen (Len u) = Len $ ceilDivPower2 (getLgMul (lgMul :: LgMul v u)) u
 
 {-# INLINE coarseRem #-}
-coarseRem ::  forall u v n. (Bits n, LgMultiple v u) => Len u n -> (Len v n, Len u n)
+coarseRem ::  forall u v n. (Bits n, Num n, LgMultiple v u) => Len u n -> (Len v n, Len u n)
 coarseRem (Len u) = let s = getLgMul (lgMul :: LgMul v u) in (Len $ u `shiftR` s, Len $ u .&. ((1 `shiftL` s) - 1))
 
+ceilDivPower2 :: (Num a, Bits a) => Int -> a -> a
 ceilDivPower2 n x = (x + ((1 `shiftL` n) - 1)) `shiftR` n
+roundUpPower2 :: (Num a, Bits a) => Int -> a -> a
 roundUpPower2 n x = ceilDivPower2 n x `shiftL` n
 
 instance Super a b => Super (Len u a) (Len u b) where super = injectionM' (inv struct) . super . injectionM' struct
src/Cgm/System/Endian.hs view
@@ -42,7 +42,7 @@ import Cgm.Control.InFunctor
 import Cgm.Control.Combinators
 
-class (Prim w, Bits w) => Endian w where 
+class (Prim w, Bits w, Num w) => Endian w where 
   untypedSwapBytes :: w -> w
 
 instance Endian Word8 where 
@@ -64,16 +64,17 @@ 
 {-# INLINE swapHalves #-} 
 swapHalves :: forall w. Bits w => w -> w
-swapHalves w = w `shiftR` halfBitSize + w `shiftL` halfBitSize where
+swapHalves w = w `shiftR` halfBitSize .|. w `shiftL` halfBitSize where
   halfBitSize = bitSize (undefined :: w) `div` 2
 
+-- | Exchange bits in mask with bits at some specified relative position (the last bits must not be in the mask)
 {-# INLINE swapMask #-} 
 swapMask :: Bits w => w -> Int -> w -> w
-swapMask mask shift w = ((w `shiftR` shift) .&. mask) + ((w .&. mask) `shiftL` shift)
+swapMask mask shift w = ((w `shiftR` shift) .&. mask) .|. ((w .&. mask) `shiftL` shift)
 
--- Number with byte value n in the nth byte, in order of increasing significance (starting at 0)
+-- | Number with byte value n in the nth byte, in order of increasing significance (starting at 0)
 byteNumbers :: forall w. Endian w => w
-byteNumbers = sum $ fmap (\n -> fromIntegral n `shiftL` (8 * fromIntegral n)) $ (at :: At w) increasingBytes
+byteNumbers = foldr (.|.) 0 $ fmap (\n -> fromIntegral n `shiftL` (8 * fromIntegral n)) $ (at :: At w) increasingBytes
 
 increasingBytes :: forall w. Prim w => Tagged w [Word8]
 increasingBytes = Tagged $ range (0, fromIntegral (primSizeOf (undefined :: w)) - 1)