tagged-0.8.7: Haskell 98 phantom types to avoid unsafely passing dummy arguments
Copyright 2009-2015 Edward Kmett
License BSD3
Maintainer Edward Kmett <ekmett@gmail.com>
Stability experimental
Portability portable
Safe Haskell Safe
Language Haskell98

Data.Tagged

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

Instances details
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

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 :: forall (a :: k). Tagged s a -> Rep1 ( Tagged s) a Source #

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

Monad ( Tagged s) Source #
Instance details

Defined in Data.Tagged

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

Foldable ( Tagged s) Source #
Instance details

Defined in Data.Tagged

Traversable ( Tagged s) Source #
Instance details

Defined in Data.Tagged

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

Read1 ( Tagged s) Source #
Instance details

Defined in Data.Tagged

Show1 ( Tagged s) Source #
Instance details

Defined in Data.Tagged

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

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

Defined in Data.Tagged

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

Defined in Data.Tagged

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

Defined in Data.Tagged

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

Defined in Data.Tagged

( 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 :: forall r r'. (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

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

Defined in Data.Tagged

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

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

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

Defined in Data.Tagged

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

Defined in Data.Tagged

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

Defined in Data.Tagged

Generic ( Tagged s b) Source #
Instance details

Defined in Data.Tagged

Associated Types

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

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

Defined in Data.Tagged

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

Defined in Data.Tagged

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

Defined in Data.Tagged

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

Defined in Data.Tagged

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.7-Hh8SrsJ8Ofo2TZerdJ0cCc" ' 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.7-Hh8SrsJ8Ofo2TZerdJ0cCc" ' 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

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.

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