| Safe Haskell | Trustworthy |
|---|---|
| Language | Haskell98 |
Data.Unique.Tag
Documentation
The Tag type is like an ad-hoc GADT allowing runtime creation of new
constructors. Specifically, it is like a GADT "enumeration" with one
phantom type.
A Tag constructor can be generated in any primitive monad (but only tags
from the same one can be compared). Every tag is equal to itself and to
no other. The GOrdering class allows rediscovery of a tag's phantom type,
so that Tags and values of type can be tested for
equality even when their types are not known to be equal.DSum (Tag s)
Tag uses a Uniq as a witness of type equality, which is sound as long
as the Uniq is truly unique and only one Tag is ever constructed from
any given Uniq. The type of newTag enforces these conditions.
veryUnsafeMkTag provides a way for adventurous (or malicious!) users to
assert that they know better than the type system.
Instances
| GEq (Tag s :: Type -> Type) Source # | |
| GCompare (Tag s :: Type -> Type) Source # | |
| GShow (Tag RealWorld) Source # | |
Defined in Unsafe.Unique.Tag | |
| Eq (Tag s a) Source # | |
| Ord (Tag s a) Source # | |
Defined in Unsafe.Unique.Tag | |
| Show (Tag RealWorld a) Source # | |
newTag :: PrimMonad m => m (Tag (PrimState m) a) Source #
Create a new tag witnessing a type a. The GEq or GOrdering instance
can be used to discover type equality of two occurrences of the same tag.
(I'm not sure whether the recovery is sound if a is instantiated as a
polymorphic type, so I'd advise caution if you intend to try it. I suspect
it is, but I have not thought through it very deeply and certainly have not
proved it.)
data RealWorld :: Type Source #
RealWorld is deeply magical. It is primitive, but it is not
unlifted (hence ptrArg). We never manipulate values of type
RealWorld; it's only used in the type system, to parameterise State#.
Instances
| Show (Uniq RealWorld) Source # | There is only one |
| GShow (Tag RealWorld) Source # | |
Defined in Unsafe.Unique.Tag | |
| Show (Tag RealWorld a) Source # | |
type (:=) = ((:~:) :: k -> k -> Type) Source #
Backwards compatibility alias; as of GHC 7.8, this is the same as `(:~:)`.
class GEq (f :: k -> Type) where Source #
A class for type-contexts which contain enough information to (at least in some cases) decide the equality of types occurring within them.
Methods
geq :: f a -> f b -> Maybe (a := b) Source #
Produce a witness of type-equality, if one exists.
A handy idiom for using this would be to pattern-bind in the Maybe monad, eg.:
extract :: GEq tag => tag a -> DSum tag -> Maybe a
extract t1 (t2 :=> x) = do
Refl <- geq t1 t2
return xOr in a list comprehension:
extractMany :: GEq tag => tag a -> [DSum tag] -> [a] extractMany t1 things = [ x | (t2 :=> x) <- things, Refl <- maybeToList (geq t1 t2)]
(Making use of the DSum type from Data.Dependent.Sum in both examples)
data GOrdering (a :: k) (b :: k) :: forall k. k -> k -> Type where Source #
A type for the result of comparing GADT constructors; the type parameters of the GADT values being compared are included so that in the case where they are equal their parameter types can be unified.
Constructors
| GLT :: forall k (a :: k) (b :: k). GOrdering a b | |
| GEQ :: forall k (a :: k) (b :: k). GOrdering a a | |
| GGT :: forall k (a :: k) (b :: k). GOrdering a b |
Instances
| GShow (GOrdering a :: k -> Type) | |
Defined in Data.GADT.Compare | |
| GRead (GOrdering a :: k -> Type) | |
Defined in Data.GADT.Compare | |
| Eq (GOrdering a b) | |
| Ord (GOrdering a b) | |
Defined in Data.GADT.Compare Methods compare :: GOrdering a b -> GOrdering a b -> Ordering Source # (<) :: GOrdering a b -> GOrdering a b -> Bool Source # (<=) :: GOrdering a b -> GOrdering a b -> Bool Source # (>) :: GOrdering a b -> GOrdering a b -> Bool Source # (>=) :: GOrdering a b -> GOrdering a b -> Bool Source # max :: GOrdering a b -> GOrdering a b -> GOrdering a b Source # min :: GOrdering a b -> GOrdering a b -> GOrdering a b Source # | |
| Show (GOrdering a b) | |