tagged-transformer-0.8.1: Monad transformer carrying an extra phantom type tag

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

Data.Functor.Trans.Tagged

Contents

Description

 

Synopsis

Tagged values

newtype TaggedT s m b Source #

A Tagged monad parameterized by:

  • s - the phantom type
  • m - the inner monad
  • b - the tagged value

| A TaggedT s m b value is a monadic value m 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 -> m b), a TaggedT s m 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"

Constructors

TagT 

Fields

Instances

MonadWriter w m => MonadWriter w (TaggedT k * s m) Source # 

Methods

writer :: (a, w) -> TaggedT k * s m a #

tell :: w -> TaggedT k * s m () #

listen :: TaggedT k * s m a -> TaggedT k * s m (a, w) #

pass :: TaggedT k * s m (a, w -> w) -> TaggedT k * s m a #

MonadState t m => MonadState t (TaggedT k * s m) Source # 

Methods

get :: TaggedT k * s m t #

put :: t -> TaggedT k * s m () #

state :: (t -> (a, t)) -> TaggedT k * s m a #

MonadReader r m => MonadReader r (TaggedT k * s m) Source # 

Methods

ask :: TaggedT k * s m r #

local :: (r -> r) -> TaggedT k * s m a -> TaggedT k * s m a #

reader :: (r -> a) -> TaggedT k * s m a #

ComonadTrans (TaggedT k * s) Source # 

Methods

lower :: Comonad w => TaggedT k * s w a -> w a #

ComonadHoist (TaggedT k * s) Source # 

Methods

cohoist :: (Comonad w, Comonad v) => (forall x. w x -> v x) -> TaggedT k * s w a -> TaggedT k * s v a #

MonadTrans (TaggedT k * s) Source # 

Methods

lift :: Monad m => m a -> TaggedT k * s m a #

Monad m => Monad (TaggedT k * s m) Source # 

Methods

(>>=) :: TaggedT k * s m a -> (a -> TaggedT k * s m b) -> TaggedT k * s m b #

(>>) :: TaggedT k * s m a -> TaggedT k * s m b -> TaggedT k * s m b #

return :: a -> TaggedT k * s m a #

fail :: String -> TaggedT k * s m a #

Functor m => Functor (TaggedT k * s m) Source # 

Methods

fmap :: (a -> b) -> TaggedT k * s m a -> TaggedT k * s m b #

(<$) :: a -> TaggedT k * s m b -> TaggedT k * s m a #

MonadFix m => MonadFix (TaggedT k * s m) Source # 

Methods

mfix :: (a -> TaggedT k * s m a) -> TaggedT k * s m a #

Applicative m => Applicative (TaggedT k * s m) Source # 

Methods

pure :: a -> TaggedT k * s m a #

(<*>) :: TaggedT k * s m (a -> b) -> TaggedT k * s m a -> TaggedT k * s m b #

liftA2 :: (a -> b -> c) -> TaggedT k * s m a -> TaggedT k * s m b -> TaggedT k * s m c #

(*>) :: TaggedT k * s m a -> TaggedT k * s m b -> TaggedT k * s m b #

(<*) :: TaggedT k * s m a -> TaggedT k * s m b -> TaggedT k * s m a #

Foldable f => Foldable (TaggedT k * s f) Source # 

Methods

fold :: Monoid m => TaggedT k * s f m -> m #

foldMap :: Monoid m => (a -> m) -> TaggedT k * s f a -> m #

foldr :: (a -> b -> b) -> b -> TaggedT k * s f a -> b #

foldr' :: (a -> b -> b) -> b -> TaggedT k * s f a -> b #

foldl :: (b -> a -> b) -> b -> TaggedT k * s f a -> b #

foldl' :: (b -> a -> b) -> b -> TaggedT k * s f a -> b #

foldr1 :: (a -> a -> a) -> TaggedT k * s f a -> a #

foldl1 :: (a -> a -> a) -> TaggedT k * s f a -> a #

toList :: TaggedT k * s f a -> [a] #

null :: TaggedT k * s f a -> Bool #

length :: TaggedT k * s f a -> Int #

elem :: Eq a => a -> TaggedT k * s f a -> Bool #

maximum :: Ord a => TaggedT k * s f a -> a #

minimum :: Ord a => TaggedT k * s f a -> a #

sum :: Num a => TaggedT k * s f a -> a #

product :: Num a => TaggedT k * s f a -> a #

Traversable f => Traversable (TaggedT k * s f) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> TaggedT k * s f a -> f (TaggedT k * s f b) #

sequenceA :: Applicative f => TaggedT k * s f (f a) -> f (TaggedT k * s f a) #

mapM :: Monad m => (a -> m b) -> TaggedT k * s f a -> m (TaggedT k * s f b) #

sequence :: Monad m => TaggedT k * s f (m a) -> m (TaggedT k * s f a) #

MonadIO m => MonadIO (TaggedT k * s m) Source # 

Methods

liftIO :: IO a -> TaggedT k * s m a #

Alternative m => Alternative (TaggedT k * s m) Source # 

Methods

empty :: TaggedT k * s m a #

(<|>) :: TaggedT k * s m a -> TaggedT k * s m a -> TaggedT k * s m a #

some :: TaggedT k * s m a -> TaggedT k * s m [a] #

many :: TaggedT k * s m a -> TaggedT k * s m [a] #

MonadPlus m => MonadPlus (TaggedT k * s m) Source # 

Methods

mzero :: TaggedT k * s m a #

mplus :: TaggedT k * s m a -> TaggedT k * s m a -> TaggedT k * s m a #

Comonad w => Comonad (TaggedT k * s w) Source # 

Methods

extract :: TaggedT k * s w a -> a #

duplicate :: TaggedT k * s w a -> TaggedT k * s w (TaggedT k * s w a) #

extend :: (TaggedT k * s w a -> b) -> TaggedT k * s w a -> TaggedT k * s w b #

Contravariant m => Contravariant (TaggedT k * s m) Source # 

Methods

contramap :: (a -> b) -> TaggedT k * s m b -> TaggedT k * s m a #

(>$) :: b -> TaggedT k * s m b -> TaggedT k * s m a #

Distributive f => Distributive (TaggedT k * s f) Source # 

Methods

distribute :: Functor f => f (TaggedT k * s f a) -> TaggedT k * s f (f a) #

collect :: Functor f => (a -> TaggedT k * s f b) -> f a -> TaggedT k * s f (f b) #

distributeM :: Monad m => m (TaggedT k * s f a) -> TaggedT k * s f (m a) #

collectM :: Monad m => (a -> TaggedT k * s f b) -> m a -> TaggedT k * s f (m b) #

MonadThrow m => MonadThrow (TaggedT k * s m) Source # 

Methods

throwM :: Exception e => e -> TaggedT k * s m a #

MonadCatch m => MonadCatch (TaggedT k * s m) Source # 

Methods

catch :: Exception e => TaggedT k * s m a -> (e -> TaggedT k * s m a) -> TaggedT k * s m a #

MonadMask m => MonadMask (TaggedT k * s m) Source # 

Methods

mask :: ((forall a. TaggedT k * s m a -> TaggedT k * s m a) -> TaggedT k * s m b) -> TaggedT k * s m b #

uninterruptibleMask :: ((forall a. TaggedT k * s m a -> TaggedT k * s m a) -> TaggedT k * s m b) -> TaggedT k * s m b #

generalBracket :: TaggedT k * s m a -> (a -> ExitCase b -> TaggedT k * s m c) -> (a -> TaggedT k * s m b) -> TaggedT k * s m (b, c) #

MonadCont m => MonadCont (TaggedT k * s m) Source # 

Methods

callCC :: ((a -> TaggedT k * s m b) -> TaggedT k * s m a) -> TaggedT k * s m a #

Plus m => Plus (TaggedT k * s m) Source # 

Methods

zero :: TaggedT k * s m a #

Alt m => Alt (TaggedT k * s m) Source # 

Methods

(<!>) :: TaggedT k * s m a -> TaggedT k * s m a -> TaggedT k * s m a #

some :: Applicative (TaggedT k * s m) => TaggedT k * s m a -> TaggedT k * s m [a] #

many :: Applicative (TaggedT k * s m) => TaggedT k * s m a -> TaggedT k * s m [a] #

Apply m => Apply (TaggedT k * s m) Source # 

Methods

(<.>) :: TaggedT k * s m (a -> b) -> TaggedT k * s m a -> TaggedT k * s m b #

(.>) :: TaggedT k * s m a -> TaggedT k * s m b -> TaggedT k * s m b #

(<.) :: TaggedT k * s m a -> TaggedT k * s m b -> TaggedT k * s m a #

liftF2 :: (a -> b -> c) -> TaggedT k * s m a -> TaggedT k * s m b -> TaggedT k * s m c #

Bind m => Bind (TaggedT k * s m) Source # 

Methods

(>>-) :: TaggedT k * s m a -> (a -> TaggedT k * s m b) -> TaggedT k * s m b #

join :: TaggedT k * s m (TaggedT k * s m a) -> TaggedT k * s m a #

Extend f => Extend (TaggedT k * s f) Source # 

Methods

duplicated :: TaggedT k * s f a -> TaggedT k * s f (TaggedT k * s f a) #

extended :: (TaggedT k * s f a -> b) -> TaggedT k * s f a -> TaggedT k * s f b #

Eq (m b) => Eq (TaggedT k1 k2 s m b) Source # 

Methods

(==) :: TaggedT k1 k2 s m b -> TaggedT k1 k2 s m b -> Bool #

(/=) :: TaggedT k1 k2 s m b -> TaggedT k1 k2 s m b -> Bool #

Ord (m b) => Ord (TaggedT k1 k2 s m b) Source # 

Methods

compare :: TaggedT k1 k2 s m b -> TaggedT k1 k2 s m b -> Ordering #

(<) :: TaggedT k1 k2 s m b -> TaggedT k1 k2 s m b -> Bool #

(<=) :: TaggedT k1 k2 s m b -> TaggedT k1 k2 s m b -> Bool #

(>) :: TaggedT k1 k2 s m b -> TaggedT k1 k2 s m b -> Bool #

(>=) :: TaggedT k1 k2 s m b -> TaggedT k1 k2 s m b -> Bool #

max :: TaggedT k1 k2 s m b -> TaggedT k1 k2 s m b -> TaggedT k1 k2 s m b #

min :: TaggedT k1 k2 s m b -> TaggedT k1 k2 s m b -> TaggedT k1 k2 s m b #

Read (m b) => Read (TaggedT k1 k2 s m b) Source # 

Methods

readsPrec :: Int -> ReadS (TaggedT k1 k2 s m b) #

readList :: ReadS [TaggedT k1 k2 s m b] #

readPrec :: ReadPrec (TaggedT k1 k2 s m b) #

readListPrec :: ReadPrec [TaggedT k1 k2 s m b] #

Show (m b) => Show (TaggedT k1 k2 s m b) Source # 

Methods

showsPrec :: Int -> TaggedT k1 k2 s m b -> ShowS #

show :: TaggedT k1 k2 s m b -> String #

showList :: [TaggedT k1 k2 s m b] -> ShowS #

type Tagged s b = TaggedT s Identity 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"

tag :: b -> Tagged s b Source #

Tag a value in Identity monad

tagT :: m b -> TaggedT s m b Source #

Easier to type alias for TagT

untag :: Tagged s b -> b Source #

Untag a value in Identity monad

retag :: TaggedT s m b -> TaggedT t m 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

mapTaggedT :: (m a -> n b) -> TaggedT s m a -> TaggedT s n b Source #

Lift an operation on underlying monad

reflected :: forall s m a. (Applicative m, Reifies s a) => TaggedT s m a Source #

Reflect reified value back in Applicative context

reflectedM :: forall s m a. (Monad m, Reifies s a) => TaggedT s m a Source #

Reflect reified value back in Monad context

asTaggedTypeOf :: s -> TaggedT s m 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.

proxy :: Tagged s b -> Proxy s -> b Source #

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

proxyT :: TaggedT s m b -> Proxy s -> m b Source #

Convert from a TaggedT 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.

unproxyT :: (Proxy s -> m a) -> TaggedT s m a Source #

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

tagSelf :: a -> Tagged a a Source #

Tag a value with its own type.

tagTSelf :: m a -> TaggedT a m a Source #

Tag a value with its own type.

untagSelf :: Tagged a a -> a Source #

untagSelf is a type-restricted version of untag.

untagTSelf :: TaggedT a m a -> m a Source #

untagSelf is a type-restricted version of untag.

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

Another way to convert a proxy to a tag.

tagTWith :: proxy s -> m a -> TaggedT s m a Source #

Another way to convert a proxy to a tag.

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

witnessT :: TaggedT a m b -> a -> m b Source #