Data.Tagged

| tagged-0.1.1: Provides newtype wrappers for phantom types to avoid unsafely passing dummy arguments | Contents | Index
Data.Tagged |
Portability | portable
Stability | experimental
Maintainer | Edward Kmett <ekmett@gmail.com>
Contents
Tagged values Proxy values Conversion
Description
Synopsis
newtype Tagged s b = Tagged {
unTagged :: b
}
retag :: Tagged s b -> Tagged t b
untag :: Tagged s b -> b
tagSelf :: a -> Tagged a a
untagSelf :: Tagged a a -> a
asTaggedTypeOf :: s -> Tagged s b -> s
data Proxy p = Proxy
reproxy :: Proxy s -> Proxy t
asProxyTypeOf :: a -> Proxy a -> a
proxy :: Tagged s a -> Proxy s -> a
unproxy :: (Proxy s -> a) -> Tagged s a
Tagged values
newtype Tagged s b
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
Tagged |
unTagged :: b |
Instances
Typeable2 Tagged |
Monad (Tagged s) |
Functor (Tagged s) |
Applicative (Tagged s) |
Foldable (Tagged s) |
Traversable (Tagged s) |
Bounded b => Bounded (Tagged s b) |
Enum b => Enum (Tagged s b) |
Eq b => Eq (Tagged s b) |
Floating b => Floating (Tagged s b) |
Fractional b => Fractional (Tagged s b) |
Integral b => Integral (Tagged s b) |
(Data s, Data b) => Data (Tagged s b) |
Num b => Num (Tagged s b) |
Ord b => Ord (Tagged s b) |
Read b => Read (Tagged s b) |
Real b => Real (Tagged s b) |
RealFloat b => RealFloat (Tagged s b) |
RealFrac b => RealFrac (Tagged s b) |
Show b => Show (Tagged s b) |
Ix b => Ix (Tagged s b) |
retag :: Tagged s b -> Tagged t b
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
Alias for `unTagged`
tagSelf :: a -> Tagged a a
Tag a value with its own type.
untagSelf :: Tagged a a -> a
`untagSelf` is a type-restricted version of `untag`.
asTaggedTypeOf :: s -> Tagged s b -> s
`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 values
data Proxy p
Constructors
Proxy |
Instances
Monad Proxy |
Functor Proxy |
Typeable1 Proxy |
Applicative Proxy |
Foldable Proxy |
Traversable Proxy |
Bounded (Proxy s) |
Enum (Proxy s) |
Eq (Proxy p) |
Data p => Data (Proxy p) |
Ord (Proxy p) |
Read (Proxy p) |
Show (Proxy p) |
Ix (Proxy s) |
Monoid (Proxy s) |
Default (Proxy s) |
reproxy :: Proxy s -> Proxy t
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
     reproxySucc :: Proxy n -> Proxy (Succ n)
     reproxySucc = reproxy
asProxyTypeOf :: a -> Proxy a -> a
`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.
Conversion
proxy :: Tagged s a -> Proxy s -> a
Convert from a `Tagged` representation to a representation based on a `Proxy`.
unproxy :: (Proxy s -> a) -> Tagged s a
Convert from a representation based on a `Proxy` to a `Tagged` representation.
Produced by Haddock version 2.7.2