Copyright | 2009-2013 Edward Kmett |
---|---|

License | BSD3 |

Maintainer | Edward Kmett <ekmett@gmail.com> |

Stability | experimental |

Portability | portable |

Safe Haskell | Trustworthy |

Language | Haskell98 |

- 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
- witness :: Tagged a b -> a -> b
- proxy :: Tagged s a -> proxy s -> a
- unproxy :: (Proxy s -> a) -> Tagged s a
- tagWith :: proxy s -> a -> Tagged s a

# Tagged values

A

value is a value `Tagged`

s b`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

can't try to use the argument `Tagged`

s b`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"

Monad (Tagged k s) | |

Functor (Tagged k s) | |

Applicative (Tagged k s) | |

Foldable (Tagged k s) | |

Traversable (Tagged k s) | |

Typeable (k -> * -> *) (Tagged k) | |

Bounded b => Bounded (Tagged k s b) | |

Enum a => Enum (Tagged k s a) | |

Eq b => Eq (Tagged k s b) | |

Floating a => Floating (Tagged k s a) | |

Fractional a => Fractional (Tagged k s a) | |

Integral a => Integral (Tagged k s a) | |

(Data s, Data b) => Data (Tagged * s b) | |

Num a => Num (Tagged k s a) | |

Ord b => Ord (Tagged k s b) | |

Read b => Read (Tagged k s b) | |

Real a => Real (Tagged k s a) | |

RealFloat a => RealFloat (Tagged k s a) | |

RealFrac a => RealFrac (Tagged k s a) | |

Show b => Show (Tagged k s b) | |

Ix b => Ix (Tagged k s b) | |

Monoid a => Monoid (Tagged k s a) |

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.