tagged-0.8.2/0000755000000000000000000000000012616210133011135 5ustar0000000000000000tagged-0.8.2/.travis.yml0000644000000000000000000001142612616210133013252 0ustar0000000000000000# This file has been generated -- see https://github.com/hvr/multi-ghc-travis language: c sudo: false cache: directories: - $HOME/.cabsnap - $HOME/.cabal/packages - $HOME/.stack before_cache: - rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log - rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.tar matrix: include: - env: CABALVER=1.16 GHCVER=7.4.2 BUILD=cabal compiler: ": #GHC 7.4.2" addons: {apt: {packages: [cabal-install-1.16,ghc-7.4.2,alex-3.1.4,happy-1.19.5], sources: [hvr-ghc]}} - env: CABALVER=1.16 GHCVER=7.6.3 BUILD=cabal compiler: ": #GHC 7.6.3" addons: {apt: {packages: [cabal-install-1.16,ghc-7.6.3,alex-3.1.4,happy-1.19.5], sources: [hvr-ghc]}} - env: CABALVER=1.18 GHCVER=7.8.4 BUILD=cabal compiler: ": #GHC 7.8.4" addons: {apt: {packages: [cabal-install-1.18,ghc-7.8.4,alex-3.1.4,happy-1.19.5], sources: [hvr-ghc]}} - env: BUILD=stack STACK_YAML=stack-7.8.yaml STACK_OPTIONS=--skip-ghc-check compiler: ": #GHC 7.8.4" addons: {apt: {packages: [cabal-install-1.18,ghc-7.8.4,alex-3.1.4,happy-1.19.5], sources: [hvr-ghc]}} - env: BUILD=stack STACK_YAML=stack-7.8.yaml os: osx - env: CABALVER=1.22 GHCVER=7.10.1 BUILD=cabal compiler: ": #GHC 7.10.1" addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.1,alex-3.1.4,happy-1.19.5], sources: [hvr-ghc]}} - env: BUILD=stack STACK_OPTIONS=--skip-ghc-check compiler: ": #GHC 7.10.1" addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.1,alex-3.1.4,happy-1.19.5], sources: [hvr-ghc]}} - env: CABALVER=1.22 GHCVER=7.10.2 BUILD=cabal compiler: ": #GHC 7.10.2" addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.2,alex-3.1.4,happy-1.19.5], sources: [hvr-ghc]}} - env: BUILD=stack os: osx before_install: - unset CC - case "$BUILD" in stack) export STACK_VERSION=0.1.3.0; mkdir -p ~/bin; travis_retry curl -L https://github.com/commercialhaskell/stack/releases/download/v$STACK_VERSION/stack-$STACK_VERSION-x86_64-$TRAVIS_OS_NAME.gz | gunzip > ~/bin/stack; chmod a+x ~/bin/stack; scripts/travis_long stack --no-terminal setup; export PATH=~/bin:$PATH;; cabal) export HAPPYVER=1.19.5 export ALEXVER=3.1.4 export PATH=~/.cabal/bin:/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:/opt/happy/$HAPPYVER/bin:/opt/alex/$ALEXVER/bin:$PATH;; esac install: - case "$BUILD" in stack) scripts/travis_long stack --no-terminal $STACK_OPTIONS build --only-snapshot -j2;; cabal) echo "$(ghc --version) [$(ghc --print-project-git-commit-id 2> /dev/null || echo '?')]" cabal --version; if [ -f $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz ]; then zcat $HOME/.cabal/packages/hackage.haskell.org/00-index.tar.gz > $HOME/.cabal/packages/hackage.haskell.org/00-index.tar; fi; travis_retry cabal update; cabal install --only-dependencies --enable-tests --enable-benchmarks --dry -v > installplan.txt; sed -i -e '1,/^Resolving /d' installplan.txt; cat installplan.txt; if diff -u installplan.txt $HOME/.cabsnap/installplan.txt; then echo "cabal build-cache HIT"; rm -rfv .ghc; cp -a $HOME/.cabsnap/ghc $HOME/.ghc; cp -a $HOME/.cabsnap/lib $HOME/.cabsnap/share $HOME/.cabsnap/bin $HOME/.cabal/; else echo "cabal build-cache MISS"; rm -rf $HOME/.cabsnap; mkdir -p $HOME/.ghc $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin; cabal install --only-dependencies --enable-tests --enable-benchmarks; if [ "$GHCVER" = "7.10.1" ]; then cabal install Cabal-1.22.4.0; fi; fi; if [ ! -d $HOME/.cabsnap ]; then echo "snapshotting package-db to build-cache"; mkdir $HOME/.cabsnap; cp -a $HOME/.ghc $HOME/.cabsnap/ghc; cp -a $HOME/.cabal/lib $HOME/.cabal/share $HOME/.cabal/bin installplan.txt $HOME/.cabsnap/; fi;; esac # snapshot package-db on cache miss # Here starts the actual work to be performed for the package under test; # any command which exits with a non-zero exit code causes the build to fail. script: - case "$BUILD" in stack) scripts/travis_long stack --no-terminal $STACK_OPTIONS build -j2;; cabal) cabal configure --enable-tests -v2; cabal build; cabal test; cabal bench || true; cabal sdist || true; SRC_TGZ=$(cabal info . | awk '{print $2;exit}').tar.gz && (cd dist && cabal install --force-reinstalls "$SRC_TGZ");; esac notifications: irc: channels: - "irc.freenode.org#haskell-lens" skip_join: true template: - "\x0313tagged\x0f/\x0306%{branch}\x0f \x0314%{commit}\x0f %{message} \x0302\x1f%{build_url}\x0f" # EOF tagged-0.8.2/CHANGELOG.markdown0000644000000000000000000000252312616210133014172 0ustar00000000000000000.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+. 0.7.2 ----- * Fixed warning on GHC 7.8 0.7.1 ----- * Added `tagWith`. 0.7 --- * `Data.Proxy` has moved into base as of GHC 7.7 for use in the new `Data.Typeable`. We no longer export it for GHC >= 7.7. The most notable change in the module from the migration into base is the loss of the `reproxy` function. 0.6.2 ----- * Allowed polymorphic arguments where possible. 0.6.1 ----- * Needlessly claim that this entirely pure package is `Trustworthy`! 0.6 --- * On GHC 7.7, we now still export the instances we used to for `Data.Proxy.Proxy` as orphans if need be. 0.5 --- * On GHC 7.7 we now simply export `Data.Typeable.Proxy` rather than make our own type. We still re-export it. 0.4.5 ----- * Added `witness` 0.4.4 ----- * Actually working polymorphic kind support 0.4.3 ----- * Added polymorphic kind support tagged-0.8.2/HLint.hs0000644000000000000000000000005312616210133012505 0ustar0000000000000000ignore "Use camelCase" ignore "Eta reduce" tagged-0.8.2/LICENSE0000644000000000000000000000276512616210133012154 0ustar0000000000000000Copyright (c) 2009-2015 Edward Kmett All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Edward Kmett nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. tagged-0.8.2/README.markdown0000644000000000000000000000014312616210133013634 0ustar0000000000000000tagged ====== Values carrying an extra [phantom type](https://wiki.haskell.org/Phantom_type) tag. tagged-0.8.2/Setup.lhs0000644000000000000000000000016512616210133012747 0ustar0000000000000000#!/usr/bin/runhaskell > module Main (main) where > import Distribution.Simple > main :: IO () > main = defaultMain tagged-0.8.2/tagged.cabal0000644000000000000000000000314312616210133013355 0ustar0000000000000000name: tagged version: 0.8.2 license: BSD3 license-file: LICENSE author: Edward A. Kmett maintainer: Edward A. Kmett stability: experimental category: Data, Phantom Types 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-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 HLint.hs source-repository head type: git location: git://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 ghc-options: -Wall hs-source-dirs: src exposed-modules: Data.Tagged if !impl(hugs) cpp-options: -DLANGUAGE_DeriveDataTypeable other-extensions: DeriveDataTypeable if impl(ghc<7.7) hs-source-dirs: old exposed-modules: Data.Proxy other-modules: Paths_tagged if impl(ghc>=7.2 && <7.5) build-depends: ghc-prim if impl(ghc>=7.6) exposed-modules: Data.Proxy.TH build-depends: template-haskell >= 2.8 && < 2.12 if flag(deepseq) build-depends: deepseq >= 1.1 && < 1.5 tagged-0.8.2/old/0000755000000000000000000000000012616210133011713 5ustar0000000000000000tagged-0.8.2/old/Data/0000755000000000000000000000000012616210133012564 5ustar0000000000000000tagged-0.8.2/old/Data/Proxy.hs0000644000000000000000000001143312616210133014243 0ustar0000000000000000{-# LANGUAGE CPP #-} #ifdef LANGUAGE_DeriveDataTypeable {-# LANGUAGE DeriveDataTypeable #-} #endif #if __GLASGOW_HASKELL__ >= 706 {-# LANGUAGE KindSignatures #-} {-# LANGUAGE PolyKinds #-} #endif #if __GLASGOW_HASKELL__ >= 707 {-# LANGUAGE StandaloneDeriving #-} #endif #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE Trustworthy #-} #endif {-# OPTIONS_GHC -fno-warn-orphans #-} ---------------------------------------------------------------------------- -- | -- Module : Data.Proxy -- Copyright : 2009-2013 Edward Kmett -- License : BSD3 -- -- Maintainer : Edward Kmett -- Stability : experimental -- Portability : portable -- ------------------------------------------------------------------------------- module Data.Proxy ( -- * Proxy values Proxy(..) , asProxyTypeOf , KProxy(..) ) where import Control.Applicative (Applicative(..)) #ifdef MIN_VERSION_deepseq import Control.DeepSeq (NFData(..)) #endif 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 #if __GLASGOW_HASKELL__ >= 702 import GHC.Generics (Generic) #endif #endif #if __GLASGOW_HASKELL__ >= 707 deriving instance Typeable Proxy #else data Proxy s = Proxy #if __GLASGOW_HASKELL__ >= 702 deriving Generic #endif #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 #ifdef MIN_VERSION_deepseq instance NFData (Proxy s) where rnf Proxy = () #endif 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 #-} -- | '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 #-} -- | A concrete, promotable proxy type, for use at the kind level -- There are no instances for this because it is intended at the kind level only data KProxy #if __GLASGOW_HASKELL__ >= 706 (t :: *) #else t #endif = KProxy #if defined(LANGUAGE_DeriveDataTypeable) deriving Typeable #endif tagged-0.8.2/src/0000755000000000000000000000000012616210133011724 5ustar0000000000000000tagged-0.8.2/src/Data/0000755000000000000000000000000012616210133012575 5ustar0000000000000000tagged-0.8.2/src/Data/Tagged.hs0000644000000000000000000002270212616210133014327 0ustar0000000000000000{-# LANGUAGE CPP #-} #ifdef LANGUAGE_DeriveDataTypeable {-# LANGUAGE DeriveDataTypeable #-} #endif #if __GLASGOW_HASKELL__ >= 706 {-# LANGUAGE PolyKinds #-} #endif #if __GLASGOW_HASKELL__ >= 702 {-# LANGUAGE DeriveGeneric #-} #if __GLASGOW_HASKELL__ < 710 {-# LANGUAGE Trustworthy #-} #endif #endif ---------------------------------------------------------------------------- -- | -- Module : Data.Tagged -- Copyright : 2009-2015 Edward Kmett -- License : BSD3 -- -- Maintainer : Edward Kmett -- Stability : experimental -- Portability : portable -- ------------------------------------------------------------------------------- module Data.Tagged ( -- * Tagged values Tagged(..) , retag , untag , tagSelf , untagSelf , asTaggedTypeOf , witness -- * Conversion , proxy , unproxy , tagWith -- * Proxy methods GHC dropped , reproxy ) where #if __GLASGOW_HASKELL__ >= 710 import Control.Applicative (liftA2) #else import Control.Applicative ((<$>), liftA2, Applicative(..)) import Data.Traversable (Traversable(..)) import Data.Monoid #endif import Data.Foldable (Foldable(..)) #ifdef MIN_VERSION_deepseq import Control.DeepSeq (NFData(..)) #endif import Control.Monad (liftM) #if __GLASGOW_HASKELL__ >= 709 import Data.Bifunctor #endif #ifdef __GLASGOW_HASKELL__ import Data.Data #endif import Data.Ix (Ix(..)) #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ < 707 import Data.Proxy #endif #if __GLASGOW_HASKELL__ >= 702 import GHC.Generics (Generic) #if __GLASGOW_HASKELL__ >= 706 import GHC.Generics (Generic1) #endif #endif -- | 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 -- passing in an undefined value with the type, because unlike an @(s -> b)@, -- a @'Tagged' s b@ can't try to use the argument @s@ as a real value. -- -- Moreover, you don't have to rely on the compiler to inline away the extra -- argument, because the newtype is \"free\" -- -- '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 #if __GLASGOW_HASKELL__ >= 702 , Generic #if __GLASGOW_HASKELL__ >= 706 , Generic1 #endif #endif #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 instance (Data s, Data b) => Data (Tagged s b) where gfoldl f z (Tagged b) = z Tagged `f` b toConstr _ = taggedConstr gunfold k z c = case constrIndex c of 1 -> k (z Tagged) _ -> error "gunfold" dataTypeOf _ = taggedDataType dataCast1 f = gcast1 f dataCast2 f = gcast2 f taggedConstr :: Constr taggedConstr = mkConstr taggedDataType "Tagged" [] Prefix {-# INLINE taggedConstr #-} 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) $ showString "Tagged " . showsPrec 11 b instance Read b => Read (Tagged s b) where 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 mempty = Tagged mempty mappend (Tagged a) (Tagged b) = Tagged (mappend a b) 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 #-} #endif #ifdef MIN_VERSION_deepseq instance NFData b => NFData (Tagged s b) where rnf (Tagged b) = rnf b #endif instance Applicative (Tagged s) where pure = Tagged {-# INLINE pure #-} Tagged f <*> Tagged x = Tagged (f x) {-# INLINE (<*>) #-} instance Monad (Tagged s) where return = Tagged {-# INLINE return #-} Tagged m >>= k = k m {-# INLINE (>>=) #-} _ >> n = n {-# INLINE (>>) #-} instance Foldable (Tagged s) where foldMap f (Tagged x) = f x {-# INLINE foldMap #-} fold (Tagged x) = x {-# INLINE fold #-} foldr f z (Tagged x) = f x z {-# INLINE foldr #-} foldl f z (Tagged x) = f z x {-# INLINE foldl #-} foldl1 _ (Tagged x) = x {-# INLINE foldl1 #-} foldr1 _ (Tagged x) = x {-# INLINE foldr1 #-} instance Traversable (Tagged s) where traverse f (Tagged x) = Tagged <$> f x {-# INLINE traverse #-} sequenceA (Tagged x) = Tagged <$> x {-# INLINE sequenceA #-} mapM f (Tagged x) = liftM Tagged (f x) {-# INLINE mapM #-} sequence (Tagged x) = liftM Tagged x {-# INLINE sequence #-} instance Enum a => Enum (Tagged s a) where succ = fmap succ pred = fmap pred toEnum = Tagged . toEnum fromEnum (Tagged x) = fromEnum x enumFrom (Tagged x) = map Tagged (enumFrom x) enumFromThen (Tagged x) (Tagged y) = map Tagged (enumFromThen x y) enumFromTo (Tagged x) (Tagged y) = map Tagged (enumFromTo x y) enumFromThenTo (Tagged x) (Tagged y) (Tagged z) = map Tagged (enumFromThenTo x y z) instance Num a => Num (Tagged s a) where (+) = liftA2 (+) (-) = liftA2 (-) (*) = liftA2 (*) negate = fmap negate abs = fmap abs signum = fmap signum fromInteger = Tagged . fromInteger instance Real a => Real (Tagged s a) where toRational (Tagged x) = toRational x instance Integral a => Integral (Tagged s a) where quot = liftA2 quot rem = liftA2 rem div = liftA2 div mod = liftA2 mod quotRem (Tagged x) (Tagged y) = (Tagged a, Tagged b) where (a, b) = quotRem x y divMod (Tagged x) (Tagged y) = (Tagged a, Tagged b) where (a, b) = divMod x y toInteger (Tagged x) = toInteger x instance Fractional a => Fractional (Tagged s a) where (/) = liftA2 (/) recip = fmap recip fromRational = Tagged . fromRational instance Floating a => Floating (Tagged s a) where pi = Tagged pi exp = fmap exp log = fmap log sqrt = fmap sqrt sin = fmap sin cos = fmap cos tan = fmap tan asin = fmap asin acos = fmap acos atan = fmap atan sinh = fmap sinh cosh = fmap cosh tanh = fmap tanh asinh = fmap asinh acosh = fmap acosh atanh = fmap atanh (**) = liftA2 (**) logBase = liftA2 (**) instance RealFrac a => RealFrac (Tagged s a) where properFraction (Tagged x) = (a, Tagged b) where (a, b) = properFraction x truncate (Tagged x) = truncate x round (Tagged x) = round x ceiling (Tagged x) = ceiling x floor (Tagged x) = floor x instance RealFloat a => RealFloat (Tagged s a) where floatRadix (Tagged x) = floatRadix x floatDigits (Tagged x) = floatDigits x floatRange (Tagged x) = floatRange x decodeFloat (Tagged x) = decodeFloat x encodeFloat m n = Tagged (encodeFloat m n) exponent (Tagged x) = exponent x significand = fmap significand scaleFloat n = fmap (scaleFloat n) isNaN (Tagged x) = isNaN x isInfinite (Tagged x) = isInfinite x isDenormalized (Tagged x) = isDenormalized x isNegativeZero (Tagged x) = isNegativeZero x isIEEE (Tagged x) = isIEEE x atan2 = liftA2 atan2 -- | 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'. -- -- @ -- data Succ n -- retagSucc :: 'Tagged' n a -> 'Tagged' (Succ n) a -- retagSucc = 'retag' -- @ retag :: Tagged s b -> Tagged t b retag = Tagged . unTagged {-# INLINE retag #-} -- | Alias for 'unTagged' untag :: Tagged s b -> b untag = unTagged -- | Tag a value with its own type. tagSelf :: a -> Tagged a a tagSelf = Tagged {-# INLINE tagSelf #-} -- | 'asTaggedTypeOf' 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. asTaggedTypeOf :: s -> tagged s b -> s asTaggedTypeOf = const {-# INLINE asTaggedTypeOf #-} witness :: Tagged a b -> a -> b witness (Tagged b) _ = b {-# INLINE witness #-} -- | 'untagSelf' is a type-restricted version of 'untag'. untagSelf :: Tagged a a -> a untagSelf (Tagged x) = x {-# INLINE untagSelf #-} -- | Convert from a 'Tagged' representation to a representation -- based on a 'Proxy'. proxy :: Tagged s a -> proxy s -> a proxy (Tagged x) _ = x {-# INLINE proxy #-} -- | Convert from a representation based on a 'Proxy' to a 'Tagged' -- representation. unproxy :: (Proxy s -> a) -> Tagged s a unproxy f = Tagged (f Proxy) {-# INLINE unproxy #-} -- | Another way to convert a proxy to a tag. 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-0.8.2/src/Data/Proxy/0000755000000000000000000000000012616210133013716 5ustar0000000000000000tagged-0.8.2/src/Data/Proxy/TH.hs0000644000000000000000000000570312616210133014572 0ustar0000000000000000{-# LANGUAGE CPP #-} #ifndef MIN_VERSION_template_haskell #define MIN_VERSION_template_haskell(x,y,z) 1 #endif module Data.Proxy.TH ( pr #if MIN_VERSION_template_haskell(2,8,0) , pr1 #endif ) where import Data.Char #if __GLASGOW_HASKELL__ < 710 import Data.Functor #endif #if __GLASGOW_HASKELL__ < 707 import Data.Version (showVersion) import Paths_tagged #endif import Language.Haskell.TH import Language.Haskell.TH.Quote import Language.Haskell.TH.Syntax proxy_d, proxy_tc :: Name #if __GLASGOW_HASKELL__ >= 707 proxy_d = mkNameG_d "base" "Data.Proxy" "Proxy" proxy_tc = mkNameG_tc "base" "Data.Proxy" "Proxy" #else proxy_d = mkNameG_d taggedPackageKey "Data.Proxy" "Proxy" proxy_tc = mkNameG_tc taggedPackageKey "Data.Proxy" "Proxy" -- note: On 7.10+ this would use CURRENT_PACKAGE_KEY if we still housed the key. taggedPackageKey :: String taggedPackageKey = "tagged-" ++ showVersion version #endif proxyTypeQ :: TypeQ -> TypeQ proxyTypeQ t = appT (conT proxy_tc) t proxyExpQ :: TypeQ -> ExpQ proxyExpQ t = sigE (conE proxy_d) (proxyTypeQ t) proxyPatQ :: TypeQ -> PatQ proxyPatQ t = sigP (conP proxy_d []) (proxyTypeQ t) -- | A proxy value quasiquoter. @[pr|T|]@ will splice an expression -- @Proxy::Proxy T@, while @[pr|A,B,C|]@ will splice in a value of -- @Proxy :: Proxy [A,B,C]@. -- TODO: parse a richer syntax for the types involved here so we can include spaces, applications, etc. pr :: QuasiQuoter pr = QuasiQuoter (mkProxy proxyExpQ) (mkProxy proxyPatQ) (mkProxy proxyTypeQ) undefined where mkProxy :: (TypeQ -> r) -> String -> r mkProxy p s = case ts of [h@(t:_)] | isUpper t -> p $ head <$> cons | otherwise -> p $ varT $ mkName h #if MIN_VERSION_template_haskell(2,8,0) _ -> p $ mkList <$> cons #endif where ts = map strip $ splitOn ',' s cons = mapM (conT . mkName) ts #if MIN_VERSION_template_haskell(2,8,0) mkList = foldr (AppT . AppT PromotedConsT) PromotedNilT #endif #if MIN_VERSION_template_haskell(2,8,0) -- | Like 'pr', but takes a single type, which is used to produce a -- 'Proxy' for a single-element list containing only that type. This -- is useful for passing a single type to a function that wants a list -- of types. -- TODO: parse a richer syntax for the types involved here so we can include spaces, applications, etc. pr1 :: QuasiQuoter pr1 = QuasiQuoter (mkProxy proxyExpQ) (mkProxy proxyPatQ) (mkProxy proxyTypeQ) undefined where sing x = AppT (AppT PromotedConsT x) PromotedNilT mkProxy p s = case s of t:_ | isUpper t -> p (fmap sing (conT $ mkName s)) | otherwise -> p (fmap sing (varT $ mkName s)) _ -> error "Empty string passed to pr1" #endif -- | Split on a delimiter. splitOn :: Eq a => a -> [a] -> [[a]] splitOn d = go where go [] = [] go xs = case t of [] -> [h] (_:t') -> h : go t' where (h,t) = break (== d) xs -- | Remove white space from both ends of a 'String'. strip :: String -> String strip = takeWhile (not . isSpace) . dropWhile isSpace