prim-uniq-0.1.0.1: Opaque unique identifiers in primitive state monads

Safe HaskellTrustworthy
LanguageHaskell98

Data.Unique.Tag

Synopsis

Documentation

data Tag s a Source #

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 DSum (Tag s) can be tested for equality even when their types are not known to be equal.

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) Source # 

Methods

geq :: f a -> f b -> Maybe ((Tag s := a) b) #

GCompare * (Tag s) Source # 

Methods

gcompare :: f a -> f b -> GOrdering (Tag s) a b #

GShow * (Tag RealWorld) Source # 

Methods

gshowsPrec :: Int -> t a -> ShowS #

Eq (Tag s a) Source # 

Methods

(==) :: Tag s a -> Tag s a -> Bool #

(/=) :: Tag s a -> Tag s a -> Bool #

Ord (Tag s a) Source # 

Methods

compare :: Tag s a -> Tag s a -> Ordering #

(<) :: Tag s a -> Tag s a -> Bool #

(<=) :: Tag s a -> Tag s a -> Bool #

(>) :: Tag s a -> Tag s a -> Bool #

(>=) :: Tag s a -> Tag s a -> Bool #

max :: Tag s a -> Tag s a -> Tag s a #

min :: Tag s a -> Tag s a -> Tag s a #

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 :: * #

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

There is only one RealWorld, so this instance is sound (unlike the general unsafeShowsPrecUniq). Note that there is no particular relationship between Uniq values (or the strings show turns them into) created in different executions of a program. The value they render to should be considered completely arbitrary, and the Show instance only even exists for convenience when testing code that uses Uniqs.

GShow * (Tag RealWorld) # 

Methods

gshowsPrec :: Int -> t a -> ShowS #

Show (Tag RealWorld a) # 

type (:=) = (:~:) #

Backwards compatibility alias; as of GHC 7.8, this is the same as `(:~:)`.

class GEq k f where #

A class for type-contexts which contain enough information to (at least in some cases) decide the equality of types occurring within them.

Instances

GEq k ((:=) k a) 

Methods

geq :: f a -> f b -> Maybe (((k := a) := a) b) #

GEq * (Tag s) # 

Methods

geq :: f a -> f b -> Maybe ((Tag s := a) b) #

data GOrdering k a b :: forall k. k -> k -> * where #

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 :: GOrdering k a b 
GEQ :: GOrdering k a a 
GGT :: GOrdering k a b 

Instances

GShow k (GOrdering k a) 

Methods

gshowsPrec :: Int -> t a -> ShowS #

GRead k (GOrdering k a) 

Methods

greadsPrec :: Int -> GReadS (GOrdering k a) t #

Eq (GOrdering k a b) 

Methods

(==) :: GOrdering k a b -> GOrdering k a b -> Bool #

(/=) :: GOrdering k a b -> GOrdering k a b -> Bool #

Ord (GOrdering k a b) 

Methods

compare :: GOrdering k a b -> GOrdering k a b -> Ordering #

(<) :: GOrdering k a b -> GOrdering k a b -> Bool #

(<=) :: GOrdering k a b -> GOrdering k a b -> Bool #

(>) :: GOrdering k a b -> GOrdering k a b -> Bool #

(>=) :: GOrdering k a b -> GOrdering k a b -> Bool #

max :: GOrdering k a b -> GOrdering k a b -> GOrdering k a b #

min :: GOrdering k a b -> GOrdering k a b -> GOrdering k a b #

Show (GOrdering k a b) 

Methods

showsPrec :: Int -> GOrdering k a b -> ShowS #

show :: GOrdering k a b -> String #

showList :: [GOrdering k a b] -> ShowS #

class GEq k f => GCompare k f where #

Type class for comparable GADT-like structures. When 2 things are equal, must return a witness that their parameter types are equal as well (GEQ).

Instances

GCompare k ((:=) k a) 

Methods

gcompare :: f a -> f b -> GOrdering (k := a) a b #

GCompare * (Tag s) # 

Methods

gcompare :: f a -> f b -> GOrdering (Tag s) a b #