Copyright | 2011-2013 Edward Kmett |
---|---|
License | BSD3 |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell98 |
- newtype TaggedT s m b = TagT {
- untagT :: m b
- type Tagged s b = TaggedT s Identity b
- tag :: b -> Tagged s b
- tagT :: m b -> TaggedT s m b
- untag :: Tagged s b -> b
- retag :: TaggedT s m b -> TaggedT t m b
- mapTaggedT :: (m a -> n b) -> TaggedT s m a -> TaggedT s n b
- reflected :: forall s m a. (Applicative m, Reifies s a) => TaggedT s m a
- reflectedM :: forall s m a. (Monad m, Reifies s a) => TaggedT s m a
- asTaggedTypeOf :: s -> TaggedT s m b -> s
- proxy :: Tagged s b -> Proxy s -> b
- proxyT :: TaggedT s m b -> Proxy s -> m b
- unproxy :: (Proxy s -> a) -> Tagged s a
- unproxyT :: (Proxy s -> m a) -> TaggedT s m a
- tagSelf :: a -> Tagged a a
- tagTSelf :: m a -> TaggedT a m a
- untagSelf :: Tagged a a -> a
- untagTSelf :: TaggedT a m a -> m a
- tagWith :: proxy s -> a -> Tagged s a
- tagTWith :: proxy s -> m a -> TaggedT s m a
- witness :: Tagged a b -> a -> b
- witnessT :: TaggedT a m b -> a -> m b
Tagged values
newtype TaggedT s m b Source #
A Tagged monad parameterized by:
s
- the phantom typem
- the inner monadb
- the tagged value
| A
value is a monadic value TaggedT
s m bm 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 -> m b)
,
a
can't try to use the argument TaggedT
s m bs
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"
type Tagged s b = TaggedT s Identity b Source #
A
value is a value Tagged
s bb
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 bs
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"
retag :: TaggedT s m b -> TaggedT t m b Source #
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
mapTaggedT :: (m a -> n b) -> TaggedT s m a -> TaggedT s n b Source #
Lift an operation on underlying monad
reflected :: forall s m a. (Applicative m, Reifies s a) => TaggedT s m a Source #
Reflect reified value back in Applicative
context
reflectedM :: forall s m a. (Monad m, Reifies s a) => TaggedT s m a Source #
Reflect reified value back in Monad
context
asTaggedTypeOf :: s -> TaggedT s m 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.