Portability | portable |
---|---|

Stability | experimental |

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

Safe Haskell | Trustworthy |

- newtype TaggedT s m b = TagT {
- untagT :: m b

- tag :: m b -> TaggedT s m b
- self :: Applicative m => a -> TaggedT a m a
- selfM :: Monad m => a -> TaggedT s m a
- untag :: TaggedT s m b -> m 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

# 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"

MonadReader r m => MonadReader r (TaggedT s m) | |

MonadWriter w m => MonadWriter w (TaggedT s m) | |

MonadState t m => MonadState t (TaggedT s m) | |

ComonadHoist (TaggedT s) | |

ComonadTrans (TaggedT s) | |

MonadTrans (TaggedT s) | |

Monad m => Monad (TaggedT s m) | |

Functor m => Functor (TaggedT s m) | |

MonadFix m => MonadFix (TaggedT s m) | |

MonadPlus m => MonadPlus (TaggedT s m) | |

Applicative m => Applicative (TaggedT s m) | |

Foldable f => Foldable (TaggedT s f) | |

Traversable f => Traversable (TaggedT s f) | |

Alternative m => Alternative (TaggedT s m) | |

Comonad w => Comonad (TaggedT s w) | |

Contravariant m => Contravariant (TaggedT s m) | |

Distributive f => Distributive (TaggedT s f) | |

MonadCatch m => MonadCatch (TaggedT s m) | |

Plus m => Plus (TaggedT s m) | |

Alt m => Alt (TaggedT s m) | |

Apply m => Apply (TaggedT s m) | |

Bind m => Bind (TaggedT s m) | |

Extend f => Extend (TaggedT s f) | |

MonadIO m => MonadIO (TaggedT s m) | |

MonadCont m => MonadCont (TaggedT s m) | |

Eq (m b) => Eq (TaggedT s m b) | |

Ord (m b) => Ord (TaggedT s m b) | |

Read (m b) => Read (TaggedT s m b) | |

Show (m b) => Show (TaggedT s m b) |

self :: Applicative m => a -> TaggedT a m aSource

Tag value with its own type in `Applicative`

context

retag :: TaggedT s m b -> TaggedT t m bSource

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 bSource

Lift an operation on underlying monad

reflected :: forall s m a. (Applicative m, Reifies s a) => TaggedT s m aSource

Reflect reified value back in `Applicative`

context

reflectedM :: forall s m a. (Monad m, Reifies s a) => TaggedT s m aSource

Reflect reified value back in `Monad`

context

asTaggedTypeOf :: s -> TaggedT s m b -> sSource

`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.