tagged-0.8.6: Haskell 98 phantom types to avoid unsafely passing dummy arguments

Copyright2009-2015 Edward Kmett
LicenseBSD3
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell98

Data.Tagged

Contents

Description

 
Synopsis

Tagged values

newtype Tagged s b Source #

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.

Constructors

Tagged 

Fields

Instances
Bitraversable (Tagged :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Tagged

Methods

bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Tagged a b -> f (Tagged c d) Source #

Bifoldable (Tagged :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Tagged

Methods

bifold :: Monoid m => Tagged m m -> m Source #

bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> Tagged a b -> m Source #

bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> Tagged a b -> c Source #

bifoldl :: (c -> a -> c) -> (c -> b -> c) -> c -> Tagged a b -> c Source #

Bifunctor (Tagged :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Tagged

Methods

bimap :: (a -> b) -> (c -> d) -> Tagged a c -> Tagged b d Source #

first :: (a -> b) -> Tagged a c -> Tagged b c Source #

second :: (b -> c) -> Tagged a b -> Tagged a c Source #

Eq2 (Tagged :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Tagged

Methods

liftEq2 :: (a -> b -> Bool) -> (c -> d -> Bool) -> Tagged a c -> Tagged b d -> Bool Source #

Ord2 (Tagged :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Tagged

Methods

liftCompare2 :: (a -> b -> Ordering) -> (c -> d -> Ordering) -> Tagged a c -> Tagged b d -> Ordering Source #

Read2 (Tagged :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Tagged

Methods

liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (Tagged a b) Source #

liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [Tagged a b] Source #

liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (Tagged a b) Source #

liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [Tagged a b] Source #

Show2 (Tagged :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Tagged

Methods

liftShowsPrec2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> Int -> Tagged a b -> ShowS Source #

liftShowList2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> [Tagged a b] -> ShowS Source #

Generic1 (Tagged s :: Type -> Type) Source # 
Instance details

Defined in Data.Tagged

Associated Types

type Rep1 (Tagged s) :: k -> Type Source #

Methods

from1 :: Tagged s a -> Rep1 (Tagged s) a Source #

to1 :: Rep1 (Tagged s) a -> Tagged s a Source #

Monad (Tagged s) Source # 
Instance details

Defined in Data.Tagged

Methods

(>>=) :: Tagged s a -> (a -> Tagged s b) -> Tagged s b Source #

(>>) :: Tagged s a -> Tagged s b -> Tagged s b Source #

return :: a -> Tagged s a Source #

fail :: String -> Tagged s a Source #

Functor (Tagged s) Source # 
Instance details

Defined in Data.Tagged

Methods

fmap :: (a -> b) -> Tagged s a -> Tagged s b Source #

(<$) :: a -> Tagged s b -> Tagged s a Source #

Applicative (Tagged s) Source # 
Instance details

Defined in Data.Tagged

Methods

pure :: a -> Tagged s a Source #

(<*>) :: Tagged s (a -> b) -> Tagged s a -> Tagged s b Source #

liftA2 :: (a -> b -> c) -> Tagged s a -> Tagged s b -> Tagged s c Source #

(*>) :: Tagged s a -> Tagged s b -> Tagged s b Source #

(<*) :: Tagged s a -> Tagged s b -> Tagged s a Source #

Foldable (Tagged s) Source # 
Instance details

Defined in Data.Tagged

Methods

fold :: Monoid m => Tagged s m -> m Source #

foldMap :: Monoid m => (a -> m) -> Tagged s a -> m Source #

foldr :: (a -> b -> b) -> b -> Tagged s a -> b Source #

foldr' :: (a -> b -> b) -> b -> Tagged s a -> b Source #

foldl :: (b -> a -> b) -> b -> Tagged s a -> b Source #

foldl' :: (b -> a -> b) -> b -> Tagged s a -> b Source #

foldr1 :: (a -> a -> a) -> Tagged s a -> a Source #

foldl1 :: (a -> a -> a) -> Tagged s a -> a Source #

toList :: Tagged s a -> [a] Source #

null :: Tagged s a -> Bool Source #

length :: Tagged s a -> Int Source #

elem :: Eq a => a -> Tagged s a -> Bool Source #

maximum :: Ord a => Tagged s a -> a Source #

minimum :: Ord a => Tagged s a -> a Source #

sum :: Num a => Tagged s a -> a Source #

product :: Num a => Tagged s a -> a Source #

Traversable (Tagged s) Source # 
Instance details

Defined in Data.Tagged

Methods

traverse :: Applicative f => (a -> f b) -> Tagged s a -> f (Tagged s b) Source #

sequenceA :: Applicative f => Tagged s (f a) -> f (Tagged s a) Source #

mapM :: Monad m => (a -> m b) -> Tagged s a -> m (Tagged s b) Source #

sequence :: Monad m => Tagged s (m a) -> m (Tagged s a) Source #

Eq1 (Tagged s) Source # 
Instance details

Defined in Data.Tagged

Methods

liftEq :: (a -> b -> Bool) -> Tagged s a -> Tagged s b -> Bool Source #

Ord1 (Tagged s) Source # 
Instance details

Defined in Data.Tagged

Methods

liftCompare :: (a -> b -> Ordering) -> Tagged s a -> Tagged s b -> Ordering Source #

Read1 (Tagged s) Source # 
Instance details

Defined in Data.Tagged

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Tagged s a) Source #

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Tagged s a] Source #

liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Tagged s a) Source #

liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Tagged s a] Source #

Show1 (Tagged s) Source # 
Instance details

Defined in Data.Tagged

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Tagged s a -> ShowS Source #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Tagged s a] -> ShowS Source #

Bounded b => Bounded (Tagged s b) Source # 
Instance details

Defined in Data.Tagged

Enum a => Enum (Tagged s a) Source # 
Instance details

Defined in Data.Tagged

Methods

succ :: Tagged s a -> Tagged s a Source #

pred :: Tagged s a -> Tagged s a Source #

toEnum :: Int -> Tagged s a Source #

fromEnum :: Tagged s a -> Int Source #

enumFrom :: Tagged s a -> [Tagged s a] Source #

enumFromThen :: Tagged s a -> Tagged s a -> [Tagged s a] Source #

enumFromTo :: Tagged s a -> Tagged s a -> [Tagged s a] Source #

enumFromThenTo :: Tagged s a -> Tagged s a -> Tagged s a -> [Tagged s a] Source #

Eq b => Eq (Tagged s b) Source # 
Instance details

Defined in Data.Tagged

Methods

(==) :: Tagged s b -> Tagged s b -> Bool Source #

(/=) :: Tagged s b -> Tagged s b -> Bool Source #

Floating a => Floating (Tagged s a) Source # 
Instance details

Defined in Data.Tagged

Methods

pi :: Tagged s a Source #

exp :: Tagged s a -> Tagged s a Source #

log :: Tagged s a -> Tagged s a Source #

sqrt :: Tagged s a -> Tagged s a Source #

(**) :: Tagged s a -> Tagged s a -> Tagged s a Source #

logBase :: Tagged s a -> Tagged s a -> Tagged s a Source #

sin :: Tagged s a -> Tagged s a Source #

cos :: Tagged s a -> Tagged s a Source #

tan :: Tagged s a -> Tagged s a Source #

asin :: Tagged s a -> Tagged s a Source #

acos :: Tagged s a -> Tagged s a Source #

atan :: Tagged s a -> Tagged s a Source #

sinh :: Tagged s a -> Tagged s a Source #

cosh :: Tagged s a -> Tagged s a Source #

tanh :: Tagged s a -> Tagged s a Source #

asinh :: Tagged s a -> Tagged s a Source #

acosh :: Tagged s a -> Tagged s a Source #

atanh :: Tagged s a -> Tagged s a Source #

log1p :: Tagged s a -> Tagged s a Source #

expm1 :: Tagged s a -> Tagged s a Source #

log1pexp :: Tagged s a -> Tagged s a Source #

log1mexp :: Tagged s a -> Tagged s a Source #

Fractional a => Fractional (Tagged s a) Source # 
Instance details

Defined in Data.Tagged

Methods

(/) :: Tagged s a -> Tagged s a -> Tagged s a Source #

recip :: Tagged s a -> Tagged s a Source #

fromRational :: Rational -> Tagged s a Source #

Integral a => Integral (Tagged s a) Source # 
Instance details

Defined in Data.Tagged

Methods

quot :: Tagged s a -> Tagged s a -> Tagged s a Source #

rem :: Tagged s a -> Tagged s a -> Tagged s a Source #

div :: Tagged s a -> Tagged s a -> Tagged s a Source #

mod :: Tagged s a -> Tagged s a -> Tagged s a Source #

quotRem :: Tagged s a -> Tagged s a -> (Tagged s a, Tagged s a) Source #

divMod :: Tagged s a -> Tagged s a -> (Tagged s a, Tagged s a) Source #

toInteger :: Tagged s a -> Integer Source #

(Data s, Data b) => Data (Tagged s b) Source # 
Instance details

Defined in Data.Tagged

Methods

gfoldl :: (forall d b0. Data d => c (d -> b0) -> d -> c b0) -> (forall g. g -> c g) -> Tagged s b -> c (Tagged s b) Source #

gunfold :: (forall b0 r. Data b0 => c (b0 -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Tagged s b) Source #

toConstr :: Tagged s b -> Constr Source #

dataTypeOf :: Tagged s b -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Tagged s b)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Tagged s b)) Source #

gmapT :: (forall b0. Data b0 => b0 -> b0) -> Tagged s b -> Tagged s b Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Tagged s b -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Tagged s b -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Tagged s b -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Tagged s b -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Tagged s b -> m (Tagged s b) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Tagged s b -> m (Tagged s b) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Tagged s b -> m (Tagged s b) Source #

Num a => Num (Tagged s a) Source # 
Instance details

Defined in Data.Tagged

Methods

(+) :: Tagged s a -> Tagged s a -> Tagged s a Source #

(-) :: Tagged s a -> Tagged s a -> Tagged s a Source #

(*) :: Tagged s a -> Tagged s a -> Tagged s a Source #

negate :: Tagged s a -> Tagged s a Source #

abs :: Tagged s a -> Tagged s a Source #

signum :: Tagged s a -> Tagged s a Source #

fromInteger :: Integer -> Tagged s a Source #

Ord b => Ord (Tagged s b) Source # 
Instance details

Defined in Data.Tagged

Methods

compare :: Tagged s b -> Tagged s b -> Ordering Source #

(<) :: Tagged s b -> Tagged s b -> Bool Source #

(<=) :: Tagged s b -> Tagged s b -> Bool Source #

(>) :: Tagged s b -> Tagged s b -> Bool Source #

(>=) :: Tagged s b -> Tagged s b -> Bool Source #

max :: Tagged s b -> Tagged s b -> Tagged s b Source #

min :: Tagged s b -> Tagged s b -> Tagged s b Source #

Read b => Read (Tagged s b) Source # 
Instance details

Defined in Data.Tagged

Real a => Real (Tagged s a) Source # 
Instance details

Defined in Data.Tagged

Methods

toRational :: Tagged s a -> Rational Source #

RealFloat a => RealFloat (Tagged s a) Source # 
Instance details

Defined in Data.Tagged

RealFrac a => RealFrac (Tagged s a) Source # 
Instance details

Defined in Data.Tagged

Methods

properFraction :: Integral b => Tagged s a -> (b, Tagged s a) Source #

truncate :: Integral b => Tagged s a -> b Source #

round :: Integral b => Tagged s a -> b Source #

ceiling :: Integral b => Tagged s a -> b Source #

floor :: Integral b => Tagged s a -> b Source #

Show b => Show (Tagged s b) Source # 
Instance details

Defined in Data.Tagged

Methods

showsPrec :: Int -> Tagged s b -> ShowS Source #

show :: Tagged s b -> String Source #

showList :: [Tagged s b] -> ShowS Source #

Ix b => Ix (Tagged s b) Source # 
Instance details

Defined in Data.Tagged

Methods

range :: (Tagged s b, Tagged s b) -> [Tagged s b] Source #

index :: (Tagged s b, Tagged s b) -> Tagged s b -> Int Source #

unsafeIndex :: (Tagged s b, Tagged s b) -> Tagged s b -> Int

inRange :: (Tagged s b, Tagged s b) -> Tagged s b -> Bool Source #

rangeSize :: (Tagged s b, Tagged s b) -> Int Source #

unsafeRangeSize :: (Tagged s b, Tagged s b) -> Int

IsString a => IsString (Tagged s a) Source # 
Instance details

Defined in Data.Tagged

Methods

fromString :: String -> Tagged s a Source #

Generic (Tagged s b) Source # 
Instance details

Defined in Data.Tagged

Associated Types

type Rep (Tagged s b) :: Type -> Type Source #

Methods

from :: Tagged s b -> Rep (Tagged s b) x Source #

to :: Rep (Tagged s b) x -> Tagged s b Source #

Semigroup a => Semigroup (Tagged s a) Source # 
Instance details

Defined in Data.Tagged

Methods

(<>) :: Tagged s a -> Tagged s a -> Tagged s a Source #

sconcat :: NonEmpty (Tagged s a) -> Tagged s a Source #

stimes :: Integral b => b -> Tagged s a -> Tagged s a Source #

(Semigroup a, Monoid a) => Monoid (Tagged s a) Source # 
Instance details

Defined in Data.Tagged

Methods

mempty :: Tagged s a Source #

mappend :: Tagged s a -> Tagged s a -> Tagged s a Source #

mconcat :: [Tagged s a] -> Tagged s a Source #

Storable a => Storable (Tagged s a) Source # 
Instance details

Defined in Data.Tagged

Methods

sizeOf :: Tagged s a -> Int Source #

alignment :: Tagged s a -> Int Source #

peekElemOff :: Ptr (Tagged s a) -> Int -> IO (Tagged s a) Source #

pokeElemOff :: Ptr (Tagged s a) -> Int -> Tagged s a -> IO () Source #

peekByteOff :: Ptr b -> Int -> IO (Tagged s a) Source #

pokeByteOff :: Ptr b -> Int -> Tagged s a -> IO () Source #

peek :: Ptr (Tagged s a) -> IO (Tagged s a) Source #

poke :: Ptr (Tagged s a) -> Tagged s a -> IO () Source #

Bits a => Bits (Tagged s a) Source # 
Instance details

Defined in Data.Tagged

Methods

(.&.) :: Tagged s a -> Tagged s a -> Tagged s a Source #

(.|.) :: Tagged s a -> Tagged s a -> Tagged s a Source #

xor :: Tagged s a -> Tagged s a -> Tagged s a Source #

complement :: Tagged s a -> Tagged s a Source #

shift :: Tagged s a -> Int -> Tagged s a Source #

rotate :: Tagged s a -> Int -> Tagged s a Source #

zeroBits :: Tagged s a Source #

bit :: Int -> Tagged s a Source #

setBit :: Tagged s a -> Int -> Tagged s a Source #

clearBit :: Tagged s a -> Int -> Tagged s a Source #

complementBit :: Tagged s a -> Int -> Tagged s a Source #

testBit :: Tagged s a -> Int -> Bool Source #

bitSizeMaybe :: Tagged s a -> Maybe Int Source #

bitSize :: Tagged s a -> Int Source #

isSigned :: Tagged s a -> Bool Source #

shiftL :: Tagged s a -> Int -> Tagged s a Source #

unsafeShiftL :: Tagged s a -> Int -> Tagged s a Source #

shiftR :: Tagged s a -> Int -> Tagged s a Source #

unsafeShiftR :: Tagged s a -> Int -> Tagged s a Source #

rotateL :: Tagged s a -> Int -> Tagged s a Source #

rotateR :: Tagged s a -> Int -> Tagged s a Source #

popCount :: Tagged s a -> Int Source #

FiniteBits a => FiniteBits (Tagged s a) Source # 
Instance details

Defined in Data.Tagged

NFData b => NFData (Tagged s b) Source # 
Instance details

Defined in Data.Tagged

Methods

rnf :: Tagged s b -> () Source #

type Rep1 (Tagged s :: Type -> Type) Source # 
Instance details

Defined in Data.Tagged

type Rep1 (Tagged s :: Type -> Type) = D1 (MetaData "Tagged" "Data.Tagged" "tagged-0.8.6-7rCsbGBW3bi5rsjoT5VGPV" True) (C1 (MetaCons "Tagged" PrefixI True) (S1 (MetaSel (Just "unTagged") NoSourceUnpackedness NoSourceStrictness DecidedLazy) Par1))
type Rep (Tagged s b) Source # 
Instance details

Defined in Data.Tagged

type Rep (Tagged s b) = D1 (MetaData "Tagged" "Data.Tagged" "tagged-0.8.6-7rCsbGBW3bi5rsjoT5VGPV" True) (C1 (MetaCons "Tagged" PrefixI True) (S1 (MetaSel (Just "unTagged") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 b)))

retag :: Tagged s b -> Tagged t b Source #

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

untag :: Tagged s b -> b Source #

Alias for unTagged

tagSelf :: a -> Tagged a a Source #

Tag a value with its own type.

untagSelf :: Tagged a a -> a Source #

untagSelf is a type-restricted version of untag.

asTaggedTypeOf :: s -> tagged s b -> s Source #

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.

witness :: Tagged a b -> a -> b Source #

Conversion

proxy :: Tagged s a -> proxy s -> a Source #

Convert from a Tagged representation to a representation based on a Proxy.

unproxy :: (Proxy s -> a) -> Tagged s a Source #

Convert from a representation based on a Proxy to a Tagged representation.

tagWith :: proxy s -> a -> Tagged s a Source #

Another way to convert a proxy to a tag.

Proxy methods GHC dropped

reproxy :: proxy a -> Proxy b Source #

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