packages feed

sized-types 0.3.5.1 → 0.3.5.2

raw patch · 3 files changed

+23/−24 lines, 3 filesdep ~base

Dependency ranges changed: base

Files

Data/Sized/Signed.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE ScopedTypeVariables #-}  -- | Signed, fixed sized numbers.--- +-- -- Copyright: (c) 2009 University of Kansas -- License: BSD3 --@@ -9,7 +9,7 @@ -- Stability: unstable -- Portability: ghc -module Data.Sized.Signed +module Data.Sized.Signed 	( Signed 	, toMatrix 	, fromMatrix@@ -18,34 +18,34 @@ 	, S20, S21, S22, S23, S24, S25, S26, S27, S28, S29 	, S30, S31, S32 	) where-	+ import Data.Sized.Matrix as M import Data.Sized.Ix import Data.List as L import Data.Bits -newtype Signed ix = Signed Integer +newtype Signed ix = Signed Integer --- 'toMatrix' turns a sized 'Signed' value into a 'Matrix' of 'Bool's. +-- 'toMatrix' turns a sized 'Signed' value into a 'Matrix' of 'Bool's. toMatrix :: forall ix . (Size ix) => Signed ix -> Matrix ix Bool toMatrix s@(Signed v) = matrix $ take (size (error "toMatrix" :: ix)) $ map odd $ iterate (`div` 2) v --- 'toMatrix' turns a a 'Matrix' of 'Bool's into sized 'Signed' value. +-- 'toMatrix' turns a a 'Matrix' of 'Bool's into sized 'Signed' value. fromMatrix :: (Size ix) => Matrix ix Bool -> Signed ix fromMatrix m = mkSigned $-	  sum [ n	+	  sum [ n 	      | (n,b) <- zip (iterate (* 2) 1) 			      (M.toList m) 	      , b 	      ]--- +-- mkSigned :: forall ix . (Size ix) => Integer -> Signed ix mkSigned v = res    where sz' = 2 ^ (fromIntegral bitCount :: Integer) 	 bitCount = size (error "mkUnsigned" :: ix) - 1 	 res = case divMod v sz' of-	  	(s,v') | even s    -> Signed v' -		       | otherwise -> Signed (v' - sz') +	  	(s,v') | even s    -> Signed v'+		       | otherwise -> Signed (v' - sz')  instance (Size ix) => Eq (Signed ix) where 	(Signed a) == (Signed b) = a == b@@ -57,7 +57,7 @@ 	readsPrec i str = [ (mkSigned a,r) | (a,r) <- readsPrec i str ] instance (Size ix) => Integral (Signed ix) where   	toInteger (Signed m) = m-	quotRem (Signed a) (Signed b) = +	quotRem (Signed a) (Signed b) = 		case quotRem a b of 		   (q,r) -> (mkSigned q,mkSigned r) instance (Size ix) => Num (Signed ix) where@@ -71,12 +71,10 @@ 	toRational (Signed n) = toRational n instance (Size ix) => Enum (Signed ix) where 	fromEnum (Signed n) = fromEnum n-	toEnum n = mkSigned (toInteger n)	+	toEnum n = mkSigned (toInteger n) instance (Size ix, Integral ix) => Bits (Signed ix) where-	bitSize s = f s undefined-	  where-		f :: (Size a) => Signed a -> a -> Int-		f _ ix = size ix+	bitSize s = size (undefined :: ix)+        bitSizeMaybe = Just . bitSize 	complement = fromMatrix . fmap not . toMatrix 	isSigned _ = True 	a `xor` b = fromMatrix (M.zipWith (/=) (toMatrix a) (toMatrix b))@@ -87,7 +85,8 @@  	rotate v i = fromMatrix (forAll $ \ ix -> m ! (fromIntegral ((fromIntegral ix - i) `mod` M.length m))) 		where m = toMatrix v         testBit u idx = toMatrix u ! (fromIntegral idx)-+instance (Size ix, Integral ix) => FiniteBits (Signed ix) where+    finiteBitSize s = size (undefined :: ix)  instance forall ix . (Size ix) => Bounded (Signed ix) where 	minBound = Signed (- maxMagnitude)
Data/Sized/Unsigned.hs view
@@ -69,10 +69,8 @@ 	fromEnum (Unsigned n) = fromEnum n 	toEnum n = mkUnsigned (toInteger n) instance (Size ix, Integral ix) => Bits (Unsigned ix) where-	bitSize s = f s undefined-	  where-		f :: (Size a) => Unsigned a -> a -> Int-		f _ ix = size ix+	bitSize s = size (undefined :: ix)+        bitSizeMaybe = Just . bitSize 	complement = fromMatrix . fmap not . toMatrix 	isSigned _ = False 	a `xor` b = fromMatrix (M.zipWith (/=) (toMatrix a) (toMatrix b))@@ -84,6 +82,8 @@  	rotate v i = fromMatrix (forAll $ \ ix -> m ! (fromIntegral ((fromIntegral ix - i) `mod` M.length m))) 		where m = toMatrix v         testBit u idx = toMatrix u ! (fromIntegral idx)+instance (Size ix, Integral ix) => FiniteBits (Unsigned ix) where+    finiteBitSize s = size (undefined :: ix)  instance forall ix . (Size ix) => Bounded (Unsigned ix) where 	minBound = Unsigned 0
sized-types.cabal view
@@ -1,5 +1,5 @@ Name:                sized-types-Version:             0.3.5.1+Version:             0.3.5.2 Synopsis:            Sized types in Haskell. Description:         Providing indices, matrixes, sparse matrixes, and signed and unsigned bit vectors. Category:            Language@@ -18,7 +18,7 @@   Default:     False  Library-  Build-Depends: base >= 4 && < 5, containers, array+  Build-Depends: base >= 4.7 && < 5, containers, array   Exposed-modules:        Data.Sized.Arith,        Data.Sized.Ix,@@ -61,6 +61,6 @@  source-repository this   type:     git-  location: git://github.com/gergoerdi/sized-types+  location: git://github.com/ku-fpg/sized-types   branch:   sized-types-0.3   tag:      0.3.5.1