Copyright | 2009-2015 Edward Kmett |
---|---|
License | BSD3 |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell98 |
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
- 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
- reproxy :: proxy a -> Proxy b
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"
Tagged
has kind
k -> * -> *
if the compiler supports
PolyKinds
, therefore
there is an extra
k
showing in the instance haddocks that may cause confusion.
Instances
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.