Data.Proxy

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

Portability | generalized newtype deriving
Stability | experimental
Maintainer | Edward Kmett <ekmett@gmail.com>

Data.Proxy

Contents

- Tagged values
- Conversion

Description

Synopsis

- 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

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.