tagged-transformer-0.1: Provides newtype wrappers for phantom types to avoid unsafely passing dummy arguments

Portabilityportable
Stabilityexperimental
MaintainerEdward Kmett <ekmett@gmail.com>

Control.Monad.Trans.Tagged

Contents

Description

 

Synopsis

Tagged values

newtype TaggedT s m 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

Constructors

TagT 

Fields

untagT :: m b
 

Instances

Monad m => Monad (TaggedT s m) 
Functor m => Functor (TaggedT s m) 
MonadFix m => MonadFix (TaggedT s m) 
MonadPlus m => MonadPlus (TaggedT s m) 
Applicative m => Applicative (TaggedT s m) 
Foldable f => Foldable (TaggedT s f) 
Traversable f => Traversable (TaggedT s f) 
Alternative m => Alternative (TaggedT s m) 
Eq (m b) => Eq (TaggedT s m b) 
Ord (m b) => Ord (TaggedT s m b) 
Read (m b) => Read (TaggedT s m b) 
Show (m b) => Show (TaggedT s m b) 

retag :: TaggedT s m b -> TaggedT t m bSource

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

tag :: b -> Tagged s bSource

tagSelf :: a -> Tagged a aSource

Tag a value with its own type.

untag :: Tagged s b -> bSource

untagSelf :: Tagged a a -> aSource

untagSelf is a type-restricted version of untag.

asTaggedTypeOf :: s -> TaggedT s m b -> sSource

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.