tagged 0.8.3 → 0.8.4
raw patch · 4 files changed
+89/−2 lines, 4 filesnew-uploader
Files
- CHANGELOG.markdown +5/−0
- old/Data/Proxy.hs +23/−1
- src/Data/Tagged.hs +60/−0
- tagged.cabal +1/−1
CHANGELOG.markdown view
@@ -1,3 +1,8 @@+0.8.4+-----+* Backport the `Alternative`, `MonadPlus`, and `MonadZip` instances for `Proxy` from `base-4.9`+* Add `Bits`, `FiniteBits`, `IsString`, and `Storable` instances for `Tagged`+ 0.8.3 ----- * Manual `Generic1` support to work around a bug in GHC 7.6
old/Data/Proxy.hs view
@@ -35,7 +35,11 @@ , KProxy(..) ) where -import Control.Applicative (Applicative(..))+import Control.Applicative (Applicative(..), Alternative(..))+import Control.Monad (MonadPlus(..))+#if MIN_VERSION_base(4,4,0)+import Control.Monad.Zip (MonadZip(..))+#endif #ifdef MIN_VERSION_deepseq import Control.DeepSeq (NFData(..)) #endif@@ -165,6 +169,12 @@ _ <*> _ = Proxy {-# INLINE (<*>) #-} +instance Alternative Proxy where+ empty = Proxy+ {-# INLINE empty #-}+ _ <|> _ = Proxy+ {-# INLINE (<|>) #-}+ instance Monoid (Proxy s) where mempty = Proxy {-# INLINE mempty #-}@@ -178,6 +188,18 @@ {-# INLINE return #-} _ >>= _ = Proxy {-# INLINE (>>=) #-}++instance MonadPlus Proxy where+ mzero = Proxy+ {-# INLINE mzero #-}+ mplus _ _ = Proxy+ {-# INLINE mplus #-}++#if MIN_VERSION_base(4,4,0)+instance MonadZip Proxy where+ mzipWith _ _ _ = Proxy+ {-# INLINE mzipWith #-}+#endif instance Foldable Proxy where foldMap _ _ = mempty
src/Data/Tagged.hs view
@@ -11,6 +11,8 @@ {-# LANGUAGE Trustworthy #-} #endif #endif++{-# OPTIONS_GHC -fno-warn-deprecations #-} ---------------------------------------------------------------------------- -- | -- Module : Data.Tagged@@ -48,6 +50,7 @@ import Data.Traversable (Traversable(..)) import Data.Monoid #endif+import Data.Bits import Data.Foldable (Foldable(..)) #ifdef MIN_VERSION_deepseq import Control.DeepSeq (NFData(..))@@ -66,6 +69,9 @@ #if __GLASGOW_HASKELL__ >= 800 import Data.Semigroup (Semigroup(..)) #endif+import Data.String (IsString(..))+import Foreign.Ptr (castPtr)+import Foreign.Storable (Storable(..)) #if __GLASGOW_HASKELL__ >= 702 import GHC.Generics (Generic) #if __GLASGOW_HASKELL__ >= 706@@ -292,6 +298,60 @@ isNegativeZero (Tagged x) = isNegativeZero x isIEEE (Tagged x) = isIEEE x atan2 = liftA2 atan2++instance Bits a => Bits (Tagged s a) where+ Tagged a .&. Tagged b = Tagged (a .&. b)+ Tagged a .|. Tagged b = Tagged (a .|. b)+ xor (Tagged a) (Tagged b) = Tagged (xor a b)+ complement (Tagged a) = Tagged (complement a)+ shift (Tagged a) i = Tagged (shift a i)+ shiftL (Tagged a) i = Tagged (shiftL a i)+ shiftR (Tagged a) i = Tagged (shiftR a i)+ rotate (Tagged a) i = Tagged (rotate a i)+ rotateL (Tagged a) i = Tagged (rotateL a i)+ rotateR (Tagged a) i = Tagged (rotateR a i)+ bit i = Tagged (bit i)+ setBit (Tagged a) i = Tagged (setBit a i)+ clearBit (Tagged a) i = Tagged (clearBit a i)+ complementBit (Tagged a) i = Tagged (complementBit a i)+ testBit (Tagged a) i = testBit a i+ isSigned (Tagged a) = isSigned a+ bitSize (Tagged a) = bitSize a -- deprecated, but still required :(+#if __GLASGOW_HASKELL__ >= 704+ unsafeShiftL (Tagged a) i = Tagged (unsafeShiftL a i)+ unsafeShiftR (Tagged a) i = Tagged (unsafeShiftR a i)+ popCount (Tagged a) = popCount a+#endif+#if __GLASGOW_HASKELL__ >= 708+ bitSizeMaybe (Tagged a) = bitSizeMaybe a+ zeroBits = Tagged zeroBits+#endif++#if __GLASGOW_HASKELL__ >= 708+instance FiniteBits a => FiniteBits (Tagged s a) where+ finiteBitSize (Tagged a) = finiteBitSize a+# if __GLASGOW_HASKELL__ >= 710+ countLeadingZeros (Tagged a) = countLeadingZeros a+ countTrailingZeros (Tagged a) = countTrailingZeros a+# endif+#endif++instance IsString a => IsString (Tagged s a) where+ fromString = Tagged . fromString++instance Storable a => Storable (Tagged s a) where+ sizeOf t = sizeOf a+ where+ Tagged a = Tagged undefined `asTypeOf` t+ alignment t = alignment a+ where+ Tagged a = Tagged undefined `asTypeOf` t+ peek ptr = Tagged <$> peek (castPtr ptr)+ poke ptr (Tagged a) = poke (castPtr ptr) a+ peekElemOff ptr i = Tagged <$> peekElemOff (castPtr ptr) i+ pokeElemOff ptr i (Tagged a) = pokeElemOff (castPtr ptr) i a+ peekByteOff ptr i = Tagged <$> peekByteOff (castPtr ptr) i+ pokeByteOff ptr i (Tagged a) = pokeByteOff (castPtr ptr) i a -- | Some times you need to change the tag you have lying around. -- Idiomatic usage is to make a new combinator for the relationship between the
tagged.cabal view
@@ -1,5 +1,5 @@ name: tagged-version: 0.8.3+version: 0.8.4 license: BSD3 license-file: LICENSE author: Edward A. Kmett