tagged 0.7.3 → 0.9
raw patch · 8 files changed
Files
- .hlint.yaml +4/−0
- .travis.yml +0/−1
- CHANGELOG.markdown +86/−0
- LICENSE +1/−1
- README.markdown +3/−1
- old/Data/Proxy.hs +0/−185
- src/Data/Tagged.hs +162/−45
- tagged.cabal +38/−13
+ .hlint.yaml view
@@ -0,0 +1,4 @@+- arguments: [--cpp-define=HLINT, --cpp-ansi]++- ignore: {name: Use camelCase}+- ignore: {name: Eta reduce}
− .travis.yml
@@ -1,1 +0,0 @@-language: haskell
CHANGELOG.markdown view
@@ -1,3 +1,89 @@+0.9 [2026.09.28]+----------------+* Remove `Data.Proxy.TH`, as its functionality has been subsumed+ by using `Proxy` with `TypeApplications` syntax. This completes the+ deprecation cycle that was introduced in `tagged-0.8.10`.++0.8.11 [2026.09.28]+-------------------+* Include `Data` and `Generic` instances for `Tagged` when building with+ MicroHs.++0.8.10 [2025.12.07]+-------------------+* Deprecate `Data.Proxy.TH.{pr,pr1}`, as their functionality has been subsumed+ by using `Proxy` with `TypeApplications` syntax. For instance, uses of+ `[pr|T|]` should be migrated to `Proxy @T`. `Data.Proxy.TH` will be removed+ in the next `tagged` release.+* Allow disabling the `template-haskell` dependency by disabling a `cabal` flag+ of the same name.+* Support building with MicroHs.++0.8.9 [2024.12.03]+------------------+* Allow building with GHC 9.12.+* Drop support for GHC 7.10 and earlier.++0.8.8 [2023.08.08]+------------------+* Allow building with GHC 9.8.++0.8.7 [2023.02.18]+------------------+* Define `Foldable1` and `Bifoldable1` instances for `Tagged`. These instances+ were originally defined in the `semigroupoids` library, and they have now+ been migrated to `tagged` as a side effect of adapting to+ [this Core Libraries Proposal](https://github.com/haskell/core-libraries-committee/issues/9),+ which adds `Foldable1` and `Bifoldable1` to `base`.++0.8.6.1 [2020.12.28]+--------------------+* Mark all modules as explicitly Safe or Trustworthy.++0.8.6 [2018.07.02]+------------------+* Make the `Read(1)` instances for `Proxy` ignore the precedence argument,+ mirroring similar changes to `base`+ [here](http://git.haskell.org/ghc.git/commitdiff/8fd959998e900dffdb7f752fcd42df7aaedeae6e).+* Fix a bug in the `Floating` instance for `Tagged` in which `logBase` was+ defined in terms of `(**)`.+* Avoid incurring some dependencies when using recent GHCs.++0.8.5+-----+* Support `Data.Bifoldable`/`Data.Bitraversable` in `base` for GHC 8.1+.+* Backport the `Eq1`, `Ord1`, `Read1`, and `Show1` instances for `Proxy` from `base-4.9`+* Add `Eq1`/`2`, `Ord1`/`2`, `Read1`/`2`, and `Show1`/`2` instances for `Tagged`++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+* Invert the dependency to supply the `Semigroup` instance ourselves when building on GHC 8++0.8.2+-------+* `deepseq` support.+* Widened `template-haskell` dependency bounds.++0.8.1+-----+* Add `KProxy` to the backwards compatibility `Data.Proxy` module.+* Add a `Generic` instance to `Proxy`.++0.8.0.1+-------+* Fix builds on GHC 7.4.++0.8+---+* Added `Data.Proxy.TH`, based on the code from `Frames` by Anthony Cowley.+* Removed `reproxy` from `Data.Proxy`. This is a bad API decision, but it isn't present in GHC's `Data.Proxy`, and this makes the API more stable.+ 0.7.3 --- * Support `Data.Bifunctor` in `base` for GHC 7.9+.
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2009-2013 Edward Kmett+Copyright (c) 2009-2015 Edward Kmett All rights reserved. Redistribution and use in source and binary forms, with or without
README.markdown view
@@ -1,4 +1,6 @@ tagged ====== -Values carrying an extra [phantom type](http://www.haskell.org/haskellwiki/Phantom_type) tag.+[](https://hackage.haskell.org/package/tagged) [](https://github.com/ekmett/tagged/actions?query=workflow%3AHaskell-CI)++Values carrying an extra [phantom type](https://wiki.haskell.org/Phantom_type) tag.
− old/Data/Proxy.hs
@@ -1,185 +0,0 @@-{-# LANGUAGE CPP #-}-#ifdef LANGUAGE_DeriveDataTypeable-{-# LANGUAGE DeriveDataTypeable #-}-#endif-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706-{-# LANGUAGE PolyKinds #-}-#endif-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 707-{-# LANGUAGE StandaloneDeriving #-}-#endif-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702-{-# LANGUAGE Trustworthy #-}-#endif-{-# OPTIONS_GHC -fno-warn-orphans #-}-------------------------------------------------------------------------------- |--- Module : Data.Proxy--- Copyright : 2009-2013 Edward Kmett--- License : BSD3------ Maintainer : Edward Kmett <ekmett@gmail.com>--- Stability : experimental--- Portability : portable------------------------------------------------------------------------------------module Data.Proxy- (- -- * Proxy values- Proxy(..)- , reproxy- , asProxyTypeOf- ) where--import Control.Applicative (Applicative(..))-import Data.Traversable (Traversable(..))-import Data.Foldable (Foldable(..))-import Data.Ix (Ix(..))-import Data.Monoid-#ifdef __GLASGOW_HASKELL__-import GHC.Arr (unsafeIndex, unsafeRangeSize)-import Data.Data-#endif--#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 707-deriving instance Typeable Proxy-#else-data Proxy s = Proxy-#endif--instance Eq (Proxy s) where- _ == _ = True--instance Ord (Proxy s) where- compare _ _ = EQ--instance Show (Proxy s) where- showsPrec _ _ = showString "Proxy"--instance Read (Proxy s) where- readsPrec d = readParen (d > 10) (\r -> [(Proxy, s) | ("Proxy",s) <- lex r ])--#ifdef __GLASGOW_HASKELL__-#if __GLASGOW_HASKELL__ < 707-instance Typeable1 Proxy where- typeOf1 _ = mkTyConApp proxyTyCon []--proxyTyCon :: TyCon-#if __GLASGOW_HASKELL__ < 704-proxyTyCon = mkTyCon "Data.Proxy.Proxy"-#else-proxyTyCon = mkTyCon3 "tagged" "Data.Proxy" "Proxy"-#endif-{-# NOINLINE proxyTyCon #-}-#endif--instance Data s => Data (Proxy s) where- gfoldl _ z _ = z Proxy- toConstr _ = proxyConstr- gunfold _ z c = case constrIndex c of- 1 -> z Proxy- _ -> error "gunfold"- dataTypeOf _ = proxyDataType- dataCast1 f = gcast1 f--proxyConstr :: Constr-proxyConstr = mkConstr proxyDataType "Proxy" [] Prefix-{-# NOINLINE proxyConstr #-}--proxyDataType :: DataType-proxyDataType = mkDataType "Data.Proxy.Proxy" [proxyConstr]-{-# NOINLINE proxyDataType #-}-#endif--instance Enum (Proxy s) where- succ _ = error "Proxy.succ"- pred _ = error "Proxy.pred"- fromEnum _ = 0- toEnum 0 = Proxy- toEnum _ = error "Proxy.toEnum: 0 expected"- enumFrom _ = [Proxy]- enumFromThen _ _ = [Proxy]- enumFromThenTo _ _ _ = [Proxy]- enumFromTo _ _ = [Proxy]--instance Ix (Proxy s) where- range _ = [Proxy]- index _ _ = 0- inRange _ _ = True- rangeSize _ = 1-#ifdef __GLASGOW_HASKELL__- unsafeIndex _ _ = 0- unsafeRangeSize _ = 1-#endif--instance Bounded (Proxy s) where- minBound = Proxy- maxBound = Proxy--instance Functor Proxy where- fmap _ _ = Proxy- {-# INLINE fmap #-}--instance Applicative Proxy where- pure _ = Proxy- {-# INLINE pure #-}- _ <*> _ = Proxy- {-# INLINE (<*>) #-}--instance Monoid (Proxy s) where- mempty = Proxy- {-# INLINE mempty #-}- mappend _ _ = Proxy- {-# INLINE mappend #-}- mconcat _ = Proxy- {-# INLINE mconcat #-}--instance Monad Proxy where- return _ = Proxy- {-# INLINE return #-}- _ >>= _ = Proxy- {-# INLINE (>>=) #-}--instance Foldable Proxy where- foldMap _ _ = mempty- {-# INLINE foldMap #-}- fold _ = mempty- {-# INLINE fold #-}- foldr _ z _ = z- {-# INLINE foldr #-}- foldl _ z _ = z- {-# INLINE foldl #-}- foldl1 _ _ = error "foldl1: Proxy"- {-# INLINE foldl1 #-}- foldr1 _ _ = error "foldr1: Proxy"- {-# INLINE foldr1 #-}--instance Traversable Proxy where- traverse _ _ = pure Proxy- {-# INLINE traverse #-}- sequenceA _ = pure Proxy- {-# INLINE sequenceA #-}- mapM _ _ = return Proxy- {-# INLINE mapM #-}- sequence _ = return Proxy- {-# INLINE sequence #-}---- | Some times you need to change the proxy you have lying around.--- Idiomatic usage is to make a new combinator for the relationship--- between the proxies that you want to enforce, and define that--- combinator using 'reproxy'.------ > data Succ n--- > reproxySucc :: proxy n -> Proxy (Succ n)--- > reproxySucc = reproxy-reproxy :: proxy s -> Proxy t-reproxy _ = Proxy-{-# INLINE reproxy #-}---- | 'asProxyTypeOf' is a type-restricted version of 'const'.--- It is usually used as an infix operator, and its typing forces its first--- argument (which is usually overloaded) to have the same type as the tag--- of the second.-asProxyTypeOf :: a -> proxy a -> a-asProxyTypeOf = const-{-# INLINE asProxyTypeOf #-}
src/Data/Tagged.hs view
@@ -1,17 +1,13 @@ {-# LANGUAGE CPP #-}-#ifdef LANGUAGE_DeriveDataTypeable-{-# LANGUAGE DeriveDataTypeable #-}-#endif-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 706+{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE PolyKinds #-}-#endif-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702-{-# LANGUAGE Trustworthy #-}-#endif+{-# LANGUAGE Safe #-}++{-# OPTIONS_GHC -Wno-deprecations #-} ---------------------------------------------------------------------------- -- | -- Module : Data.Tagged--- Copyright : 2009-2013 Edward Kmett+-- Copyright : 2009-2015 Edward Kmett -- License : BSD3 -- -- Maintainer : Edward Kmett <ekmett@gmail.com>@@ -34,23 +30,41 @@ , proxy , unproxy , tagWith+ -- * Proxy methods GHC dropped+ , reproxy ) where -import Control.Applicative ((<$>), liftA2, Applicative(..))+#if !(MIN_VERSION_base(4,18,0))+import Control.Applicative (liftA2)+#endif+import Data.Bits+import Data.Foldable (Foldable(..))+#ifdef MIN_VERSION_deepseq+import Control.DeepSeq (NFData(..))+#endif+import Data.Functor.Classes ( Eq1(..), Ord1(..), Read1(..), Show1(..)+ , Eq2(..), Ord2(..), Read2(..), Show2(..)+ ) import Control.Monad (liftM)-#if __GLASGOW_HASKELL__ >= 709 import Data.Bifunctor+#if MIN_VERSION_base(4,10,0)+import Data.Bifoldable (Bifoldable(..))+import Data.Bitraversable (Bitraversable(..)) #endif-import Data.Traversable (Traversable(..))-import Data.Foldable (Foldable(..))-#ifdef __GLASGOW_HASKELL__-import Data.Data+#if MIN_VERSION_base(4,18,0)+import Data.Foldable1 (Foldable1(..))+import Data.Bifoldable1 (Bifoldable1(..)) #endif+import Data.Data import Data.Ix (Ix(..))-import Data.Monoid-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ < 707-import Data.Proxy+import Data.Semigroup (Semigroup(..))+import Data.String (IsString(..))+#ifdef __MHS__+import Data.Traversable (Traversable(..)) #endif+import Foreign.Ptr (castPtr)+import Foreign.Storable (Storable(..))+import GHC.Generics (Generic, Generic1) -- | A @'Tagged' s b@ value is a value @b@ with an attached phantom type @s@. -- This can be used in place of the more traditional but less safe idiom of@@ -59,26 +73,11 @@ -- -- Moreover, you don't have to rely on the compiler to inline away the extra -- argument, because the newtype is \"free\"-newtype Tagged s b = Tagged { unTagged :: b } deriving- ( Eq, Ord, Ix, Bounded-#if __GLASGOW_HASKELL__ >= 707- , Typeable-#endif- )--#ifdef __GLASGOW_HASKELL__-#if __GLASGOW_HASKELL__ < 707-instance Typeable2 Tagged where- typeOf2 _ = mkTyConApp taggedTyCon []--taggedTyCon :: TyCon-#if __GLASGOW_HASKELL__ < 704-taggedTyCon = mkTyCon "Data.Tagged.Tagged"-#else-taggedTyCon = mkTyCon3 "tagged" "Data.Tagged" "Tagged"-#endif--#endif+--+-- 'Tagged' has kind @k -> * -> *@ if the compiler supports @PolyKinds@, therefore+-- there is an extra @k@ showing in the instance haddocks that may cause confusion.+newtype Tagged s b = Tagged { unTagged :: b }+ deriving (Eq, Ord, Ix, Bounded, Generic, Generic1) instance (Data s, Data b) => Data (Tagged s b) where gfoldl f z (Tagged b) = z Tagged `f` b@@ -97,7 +96,6 @@ taggedDataType :: DataType taggedDataType = mkDataType "Data.Tagged.Tagged" [taggedConstr] {-# INLINE taggedDataType #-}-#endif instance Show b => Show (Tagged s b) where showsPrec n (Tagged b) = showParen (n > 10) $@@ -108,33 +106,93 @@ readsPrec d = readParen (d > 10) $ \r -> [(Tagged a, t) | ("Tagged", s) <- lex r, (a, t) <- readsPrec 11 s] -instance Monoid a => Monoid (Tagged s a) where+instance Semigroup a => Semigroup (Tagged s a) where+ Tagged a <> Tagged b = Tagged (a <> b)+ stimes n (Tagged a) = Tagged (stimes n a)++instance (Semigroup a, Monoid a) => Monoid (Tagged s a) where mempty = Tagged mempty- mappend (Tagged a) (Tagged b) = Tagged (mappend a b)+ mappend = (<>) instance Functor (Tagged s) where fmap f (Tagged x) = Tagged (f x) {-# INLINE fmap #-} -#if __GLASGOW_HASKELL__ >= 709 -- this instance is provided by the bifunctors package for GHC<7.9 instance Bifunctor Tagged where bimap _ g (Tagged b) = Tagged (g b) {-# INLINE bimap #-}++#if MIN_VERSION_base(4,10,0)+-- these instances are provided by the bifunctors package for GHC<8.1+instance Bifoldable Tagged where+ bifoldMap _ g (Tagged b) = g b+ {-# INLINE bifoldMap #-}++instance Bitraversable Tagged where+ bitraverse _ g (Tagged b) = Tagged <$> g b+ {-# INLINE bitraverse #-} #endif +#if MIN_VERSION_base(4,18,0)+instance Foldable1 (Tagged a) where+ foldMap1 f (Tagged a) = f a+ {-# INLINE foldMap1 #-}++instance Bifoldable1 Tagged where+ bifoldMap1 _ g (Tagged b) = g b+ {-# INLINE bifoldMap1 #-}+#endif++#ifdef MIN_VERSION_deepseq+instance NFData b => NFData (Tagged s b) where+ rnf (Tagged b) = rnf b+#endif++instance Eq1 (Tagged s) where+ liftEq eq (Tagged a) (Tagged b) = eq a b++instance Ord1 (Tagged s) where+ liftCompare cmp (Tagged a) (Tagged b) = cmp a b++instance Read1 (Tagged s) where+ liftReadsPrec rp _ d = readParen (d > 10) $ \r ->+ [(Tagged a, t) | ("Tagged", s) <- lex r, (a, t) <- rp 11 s]++instance Show1 (Tagged s) where+ liftShowsPrec sp _ n (Tagged b) = showParen (n > 10) $+ showString "Tagged " .+ sp 11 b++instance Eq2 Tagged where+ liftEq2 _ eq (Tagged a) (Tagged b) = eq a b++instance Ord2 Tagged where+ liftCompare2 _ cmp (Tagged a) (Tagged b) = cmp a b++instance Read2 Tagged where+ liftReadsPrec2 _ _ rp _ d = readParen (d > 10) $ \r ->+ [(Tagged a, t) | ("Tagged", s) <- lex r, (a, t) <- rp 11 s]++instance Show2 Tagged where+ liftShowsPrec2 _ _ sp _ n (Tagged b) = showParen (n > 10) $+ showString "Tagged " .+ sp 11 b+ instance Applicative (Tagged s) where pure = Tagged {-# INLINE pure #-} Tagged f <*> Tagged x = Tagged (f x) {-# INLINE (<*>) #-}+ _ *> n = n+ {-# INLINE (*>) #-} instance Monad (Tagged s) where- return = Tagged+ return = pure {-# INLINE return #-} Tagged m >>= k = k m {-# INLINE (>>=) #-}- _ >> n = n+ (>>) = (*>) {-# INLINE (>>) #-} instance Foldable (Tagged s) where@@ -218,7 +276,7 @@ acosh = fmap acosh atanh = fmap atanh (**) = liftA2 (**)- logBase = liftA2 (**)+ logBase = liftA2 logBase instance RealFrac a => RealFrac (Tagged s a) where properFraction (Tagged x) = (a, Tagged b) where@@ -244,6 +302,52 @@ 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 :(+ unsafeShiftL (Tagged a) i = Tagged (unsafeShiftL a i)+ unsafeShiftR (Tagged a) i = Tagged (unsafeShiftR a i)+ popCount (Tagged a) = popCount a+ bitSizeMaybe (Tagged a) = bitSizeMaybe a+ zeroBits = Tagged zeroBits++instance FiniteBits a => FiniteBits (Tagged s a) where+ finiteBitSize (Tagged a) = finiteBitSize a+ countLeadingZeros (Tagged a) = countLeadingZeros a+ countTrailingZeros (Tagged a) = countTrailingZeros a++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 -- tags that you want to enforce, and define that combinator using 'retag'.@@ -296,3 +400,16 @@ tagWith :: proxy s -> a -> Tagged s a tagWith _ = Tagged {-# INLINE tagWith #-}++-- | Some times you need to change the proxy you have lying around.+-- Idiomatic usage is to make a new combinator for the relationship+-- between the proxies that you want to enforce, and define that+-- combinator using 'reproxy'.+--+-- @+-- data Succ n+-- reproxySucc :: proxy n -> 'Proxy' (Succ n)+-- reproxySucc = 'reproxy'+-- @+reproxy :: proxy a -> Proxy b+reproxy _ = Proxy
tagged.cabal view
@@ -1,5 +1,5 @@ name: tagged-version: 0.7.3+version: 0.9 license: BSD3 license-file: LICENSE author: Edward A. Kmett@@ -9,28 +9,53 @@ synopsis: Haskell 98 phantom types to avoid unsafely passing dummy arguments homepage: http://github.com/ekmett/tagged bug-reports: http://github.com/ekmett/tagged/issues-copyright: 2009-2013 Edward A. Kmett-description: Haskell 98 phantom types to avoid unsafely passing dummy arguments+copyright: 2009-2015 Edward A. Kmett+description: Haskell 98 phantom types to avoid unsafely passing dummy arguments. build-type: Simple cabal-version: >= 1.10-extra-source-files: .travis.yml CHANGELOG.markdown README.markdown+extra-source-files: .hlint.yaml CHANGELOG.markdown README.markdown+tested-with:+ GHC == 8.0.2+ GHC == 8.2.2+ GHC == 8.4.4+ GHC == 8.6.5+ GHC == 8.8.4+ GHC == 8.10.7+ GHC == 9.0.2+ GHC == 9.2.8+ GHC == 9.4.8+ GHC == 9.6.6+ GHC == 9.8.4+ GHC == 9.10.3+ GHC == 9.12.2+ GHC == 9.14.1 source-repository head type: git- location: git://github.com/ekmett/tagged.git+ location: https://github.com/ekmett/tagged.git +flag deepseq+ description:+ You can disable the use of the `deepseq` package using `-f-deepseq`.+ .+ Disabing this is an unsupported configuration, but it may be useful for accelerating builds in sandboxes for expert users.+ default: True+ manual: True+ library default-language: Haskell98 other-extensions: CPP- build-depends: base >= 2 && < 5+ build-depends:+ base >= 4.9 && < 5 ghc-options: -Wall hs-source-dirs: src- exposed-modules: Data.Tagged+ exposed-modules:+ Data.Tagged - if !impl(hugs)- cpp-options: -DLANGUAGE_DeriveDataTypeable- other-extensions: DeriveDataTypeable+ if impl(ghc >= 9.0)+ -- these flags may abort compilation with GHC-8.10+ -- https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3295+ ghc-options: -Winferred-safe-imports -Wmissing-safe-haskell-mode - if !impl(ghc>=7.7)- hs-source-dirs: old- exposed-modules: Data.Proxy+ if flag(deepseq)+ build-depends: deepseq >= 1.1 && < 1.6