Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Data.Exists
Description
Data types and type classes for working with existentially quantified
values. When Quantified Class Constraints land in GHC 8.6,
the BarForall
classes will be considered obsolete. When Dependent
Haskell lands, the BarForeach
classes will also be obsolete.
The benefit that most of the typeclasses in this module provide is
that they help populate the instances of Exists
and Rec
.
Synopsis
- data Exists (f :: k -> Type) = forall a. Exists !(f a)
- data Exists2 (f :: k -> j -> Type) = forall a b. Exists2 !(f a b)
- data Exists3 (f :: k -> j -> l -> Type) = forall a b c. Exists3 !(f a b c)
- data Some (f :: k -> Type) = forall a. Some !(Sing a) !(f a)
- data DependentPair (f :: k -> Type) (g :: k -> Type) = forall a. DependentPair (f a) (g a)
- data WitnessedEquality (a :: k) (b :: k) where
- data WitnessedOrdering (a :: k) (b :: k) where
- newtype ApplyForall f a = ApplyForall {
- getApplyForall :: f a
- newtype ApplyForeach f a = ApplyForeach {
- getApplyForeach :: f a
- newtype ApplyLifted f a = ApplyLifted {
- getApplyLifted :: f a
- class EqForall f where
- class EqForall f => EqForallPoly f where
- eqForallPoly :: f a -> f b -> WitnessedEquality a b
- class EqForeach f where
- class EqForall f => OrdForall f where
- compareForall :: f a -> f a -> Ordering
- class (OrdForall f, EqForallPoly f) => OrdForallPoly f where
- compareForallPoly :: f a -> f b -> WitnessedOrdering a b
- class EqForeach f => OrdForeach f where
- compareForeach :: Sing a -> f a -> f a -> Ordering
- class ShowForall f where
- showsPrecForall :: Int -> f a -> ShowS
- class ShowForeach f where
- showsPrecForeach :: Sing a -> Int -> f a -> ShowS
- class ReadExists f where
- readPrecExists :: ReadPrec (Exists f)
- class EnumForall f where
- toEnumForall :: Int -> f a
- fromEnumForall :: f a -> Int
- class EnumExists f where
- toEnumExists :: Int -> Exists f
- fromEnumExists :: Exists f -> Int
- class BoundedExists f where
- minBoundExists :: Exists f
- maxBoundExists :: Exists f
- class SemigroupForall f where
- appendForall :: f a -> f a -> f a
- class SemigroupForeach f where
- appendForeach :: Sing a -> f a -> f a -> f a
- class SemigroupForall f => MonoidForall f where
- emptyForall :: f a
- class SemigroupForeach f => MonoidForeach f where
- emptyForeach :: Sing a -> f a
- class HashableForall f where
- hashWithSaltForall :: Int -> f a -> Int
- class HashableForeach f where
- hashWithSaltForeach :: Sing a -> Int -> f a -> Int
- class PathPieceExists f where
- fromPathPieceForall :: Text -> Maybe (Exists f)
- toPathPieceForall :: Exists f -> Text
- class StorableForeach (f :: k -> Type) where
- peekForeach :: Sing a -> Ptr (f a) -> IO (f a)
- pokeForeach :: Sing a -> Ptr (f a) -> f a -> IO ()
- sizeOfForeach :: forall (a :: k). Proxy f -> Sing a -> Int
- class StorableForall (f :: k -> Type) where
- peekForall :: Ptr (f a) -> IO (f a)
- pokeForall :: Ptr (f a) -> f a -> IO ()
- sizeOfForall :: Proxy f -> Int
- class PrimForall (f :: k -> Type) where
- sizeOfForall# :: Proxy# f -> Int#
- alignmentForall# :: Proxy# f -> Int#
- indexByteArrayForall# :: ByteArray# -> Int# -> f a
- readByteArrayForall# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, f a #)
- writeByteArrayForall# :: MutableByteArray# s -> Int# -> f a -> State# s -> State# s
- setByteArrayForall# :: MutableByteArray# s -> Int# -> Int# -> f a -> State# s -> State# s
- indexOffAddrForall# :: Addr# -> Int# -> f a
- readOffAddrForall# :: Addr# -> Int# -> State# s -> (# State# s, f a #)
- writeOffAddrForall# :: Addr# -> Int# -> f a -> State# s -> State# s
- setOffAddrForall# :: Addr# -> Int# -> Int# -> f a -> State# s -> State# s
- class BinaryExists (f :: k -> Type) where
- class BinaryForeach (f :: k -> Type) where
- putForeach :: Sing a -> f a -> Put
- getForeach :: Sing a -> Get (f a)
- class EqForall2 f where
- class EqForallPoly2 (f :: k -> j -> Type) where
- eqForallPoly2 :: forall (a :: k) (b :: j) (c :: k) (d :: j). f a b -> f c d -> WitnessedEquality '(a, b) '(c, d)
- class ShowForall2 f where
- showsPrecForall2 :: Int -> f a b -> ShowS
- class ShowForeach2 f where
- showsPrecForeach2 :: Sing a -> Sing b -> Int -> f a b -> ShowS
- class BinaryExists2 (f :: k -> j -> Type) where
- putExists2 :: Exists2 f -> Put
- getExists2 :: Get (Exists2 f)
- type family Sing = (r :: k -> Type) | r -> k
- data SingList :: forall (k :: Type). [k] -> Type where
- SingListNil :: SingList '[]
- SingListCons :: Sing r -> SingList rs -> SingList (r ': rs)
- data SingMaybe :: Maybe k -> Type where
- SingMaybeJust :: Sing a -> SingMaybe ('Just a)
- SingMaybeNothing :: SingMaybe 'Nothing
- class Reify a where
- class Unreify k where
- class EqSing k where
- class EqSing k => OrdSing k where
- compareSing :: forall (a :: k) (b :: k). Sing a -> Sing b -> WitnessedOrdering a b
- class ShowSing k where
- showsPrecSing :: forall (a :: k). Int -> Sing a -> ShowS
- class ToSing (f :: k -> Type) where
- class SingKind k where
- demoteSing :: Sing (a :: k) -> k
- promoteSing :: k -> Exists (Sing :: k -> Type)
- showsForall :: ShowForall f => f a -> ShowS
- showsForeach :: ShowForeach f => Sing a -> f a -> ShowS
- showForall :: ShowForall f => f a -> String
- showListForall :: ShowForall f => [f a] -> ShowS
- showListForeach :: ShowForeach f => Sing a -> [f a] -> ShowS
- showsForall2 :: ShowForall2 f => f a b -> ShowS
- showForall2 :: ShowForall2 f => f a b -> String
- defaultEqForallPoly :: (TestEquality f, EqForall f) => f a -> f b -> WitnessedEquality a b
- defaultCompareForallPoly :: (TestEquality f, OrdForall f) => f a -> f b -> Ordering
- weakenEquality :: WitnessedEquality a b -> Bool
- weakenOrdering :: WitnessedOrdering a b -> Ordering
- strengthenEquality :: Bool -> WitnessedEquality a a
- strengthenOrdering :: Ordering -> WitnessedOrdering a a
- strengthenUnequalOrdering :: Ordering -> WitnessedOrdering a b
- unreifyList :: forall (k :: Type) (as :: [k]) (b :: Type). Unreify k => SingList as -> (Reify as => b) -> b
Data Types
data Exists (f :: k -> Type) Source #
Hide a type parameter.
Constructors
forall a. Exists !(f a) |
Instances
BoundedExists f => Bounded (Exists f) Source # | |
EnumExists f => Enum (Exists f) Source # | |
ReadExists f => Read (Exists f) Source # | |
ShowForall f => Show (Exists f) Source # | |
BinaryExists f => Binary (Exists f) Source # | |
EqForallPoly f => Eq (Exists f) Source # | |
OrdForallPoly f => Ord (Exists f) Source # | |
Defined in Data.Exists | |
(EqForallPoly f, HashableForall f) => Hashable (Exists f) Source # | |
Defined in Data.Exists | |
PathPieceExists f => PathPiece (Exists f) Source # | |
Defined in Data.Exists |
data Exists2 (f :: k -> j -> Type) Source #
Hide two type parameters.
Constructors
forall a b. Exists2 !(f a b) |
Instances
ShowForall2 f => Show (Exists2 f) Source # | |
BinaryExists2 f => Binary (Exists2 f) Source # | |
EqForallPoly2 f => Eq (Exists2 f) Source # | |
data Exists3 (f :: k -> j -> l -> Type) Source #
Hide three type parameters.
Constructors
forall a b c. Exists3 !(f a b c) |
data Some (f :: k -> Type) Source #
A dependent pair in which the first element is a singleton.
data DependentPair (f :: k -> Type) (g :: k -> Type) Source #
A pair in which the type of the second element can only be discovered by looking at the first element. The type instance does not enforce this, but all of its typeclass instances make this assumption.
Constructors
forall a. DependentPair (f a) (g a) |
Instances
(ShowForall f, ToSing f, ShowForeach g) => Show (DependentPair f g) Source # | |
Defined in Data.Exists Methods showsPrec :: Int -> DependentPair f g -> ShowS # show :: DependentPair f g -> String # showList :: [DependentPair f g] -> ShowS # | |
(EqForallPoly f, ToSing f, EqForeach g) => Eq (DependentPair f g) Source # | |
Defined in Data.Exists Methods (==) :: DependentPair f g -> DependentPair f g -> Bool # (/=) :: DependentPair f g -> DependentPair f g -> Bool # | |
(OrdForallPoly f, ToSing f, OrdForeach g) => Ord (DependentPair f g) Source # | |
Defined in Data.Exists Methods compare :: DependentPair f g -> DependentPair f g -> Ordering # (<) :: DependentPair f g -> DependentPair f g -> Bool # (<=) :: DependentPair f g -> DependentPair f g -> Bool # (>) :: DependentPair f g -> DependentPair f g -> Bool # (>=) :: DependentPair f g -> DependentPair f g -> Bool # max :: DependentPair f g -> DependentPair f g -> DependentPair f g # min :: DependentPair f g -> DependentPair f g -> DependentPair f g # |
data WitnessedEquality (a :: k) (b :: k) where Source #
Constructors
WitnessedEqualityEqual :: WitnessedEquality a a | |
WitnessedEqualityUnequal :: WitnessedEquality a b |
data WitnessedOrdering (a :: k) (b :: k) where Source #
Constructors
WitnessedOrderingLT :: WitnessedOrdering a b | |
WitnessedOrderingEQ :: WitnessedOrdering a a | |
WitnessedOrderingGT :: WitnessedOrdering a b |
newtype ApplyForall f a Source #
Constructors
ApplyForall | |
Fields
|
Instances
newtype ApplyForeach f a Source #
This is useful for recovering an instance of a typeclass when we have the pi-quantified variant and a singleton in scope.
Constructors
ApplyForeach | |
Fields
|
Instances
newtype ApplyLifted f a Source #
Constructors
ApplyLifted | |
Fields
|
Instances
Type Classes
class EqForall f where Source #
Instances
EqForall (Proxy :: k -> Type) Source # | |
Eq a => EqForall (Const a :: k -> Type) Source # | |
EqForall ((:~:) a :: k -> Type) Source # | |
(EqForall f, EqForall g) => EqForall (Product f g :: k -> Type) Source # | |
(EqForall f, EqForall g) => EqForall (Sum f g :: k -> Type) Source # | |
(Eq1 f, EqForall g) => EqForall (Compose f g :: k -> Type) Source # | |
EqForall (SingList :: [k] -> Type) Source # | |
class EqForall f => EqForallPoly f where Source #
Minimal complete definition
Nothing
Methods
eqForallPoly :: f a -> f b -> WitnessedEquality a b Source #
default eqForallPoly :: TestEquality f => f a -> f b -> WitnessedEquality a b Source #
Instances
(EqForallPoly f, EqForallPoly g) => EqForallPoly (Product f g :: k -> Type) Source # | |
Defined in Data.Exists Methods eqForallPoly :: forall (a :: k0) (b :: k0). Product f g a -> Product f g b -> WitnessedEquality a b Source # | |
EqSing k => EqForallPoly (SingList :: [k] -> Type) Source # | |
Defined in Data.Exists Methods eqForallPoly :: forall (a :: k0) (b :: k0). SingList a -> SingList b -> WitnessedEquality a b Source # |
class EqForeach f where Source #
Variant of EqForall
that requires a pi-quantified type.
class EqForall f => OrdForall f where Source #
Methods
compareForall :: f a -> f a -> Ordering Source #
Instances
OrdForall (Proxy :: k -> Type) Source # | |
Defined in Data.Exists | |
Ord a => OrdForall (Const a :: k -> Type) Source # | |
Defined in Data.Exists | |
(OrdForall f, OrdForall g) => OrdForall (Product f g :: k -> Type) Source # | |
Defined in Data.Exists | |
(OrdForall f, OrdForall g) => OrdForall (Sum f g :: k -> Type) Source # | |
Defined in Data.Exists |
class (OrdForall f, EqForallPoly f) => OrdForallPoly f where Source #
Methods
compareForallPoly :: f a -> f b -> WitnessedOrdering a b Source #
Instances
(OrdForallPoly f, OrdForallPoly g) => OrdForallPoly (Product f g :: k -> Type) Source # | |
Defined in Data.Exists Methods compareForallPoly :: forall (a :: k0) (b :: k0). Product f g a -> Product f g b -> WitnessedOrdering a b Source # |
class EqForeach f => OrdForeach f where Source #
Variant of OrdForall
that requires a pi-quantified type.
Methods
compareForeach :: Sing a -> f a -> f a -> Ordering Source #
Instances
OrdForeach f => OrdForeach (ApplyForeach f :: k -> Type) Source # | |
Defined in Data.Exists Methods compareForeach :: forall (a :: k0). Sing a -> ApplyForeach f a -> ApplyForeach f a -> Ordering Source # | |
(Ord1 f, OrdForeach g) => OrdForeach (Compose f g :: k -> Type) Source # | |
Defined in Data.Exists |
class ShowForall f where Source #
Methods
showsPrecForall :: Int -> f a -> ShowS Source #
Instances
ShowForall (Proxy :: k -> Type) Source # | |
Defined in Data.Exists | |
Show a => ShowForall (Const a :: k -> Type) Source # | |
Defined in Data.Exists | |
(ShowForall f, ShowForall g) => ShowForall (Product f g :: k -> Type) Source # | |
Defined in Data.Exists | |
(Show1 f, ShowForall g) => ShowForall (Compose f g :: k -> Type) Source # | |
Defined in Data.Exists |
class ShowForeach f where Source #
Instances
(Show1 f, ShowForeach g) => ShowForeach (Compose f g :: k -> Type) Source # | |
Defined in Data.Exists |
class ReadExists f where Source #
Methods
readPrecExists :: ReadPrec (Exists f) Source #
Instances
ReadExists (Proxy :: k -> Type) Source # | |
Defined in Data.Exists |
class EnumForall f where Source #
class EnumExists f where Source #
class BoundedExists f where Source #
class SemigroupForall f where Source #
Methods
appendForall :: f a -> f a -> f a Source #
Instances
SemigroupForall (Proxy :: k -> Type) Source # | |
Defined in Data.Exists | |
Semigroup a => SemigroupForall (Const a :: k -> Type) Source # | |
Defined in Data.Exists | |
SemigroupForall f => SemigroupForall (ApplyForall f :: k -> Type) Source # | |
Defined in Data.Exists Methods appendForall :: forall (a :: k0). ApplyForall f a -> ApplyForall f a -> ApplyForall f a Source # | |
(Semigroup1 f, SemigroupForall g) => SemigroupForall (Compose f g :: k -> Type) Source # | |
Defined in Data.Exists |
class SemigroupForeach f where Source #
Methods
appendForeach :: Sing a -> f a -> f a -> f a Source #
Instances
SemigroupForeach f => SemigroupForeach (ApplyForeach f :: k -> Type) Source # | |
Defined in Data.Exists Methods appendForeach :: forall (a :: k0). Sing a -> ApplyForeach f a -> ApplyForeach f a -> ApplyForeach f a Source # | |
(Semigroup1 f, SemigroupForeach g) => SemigroupForeach (Compose f g :: k -> Type) Source # | |
Defined in Data.Exists |
class SemigroupForall f => MonoidForall f where Source #
Methods
emptyForall :: f a Source #
Instances
Monoid a => MonoidForall (Const a :: k -> Type) Source # | |
Defined in Data.Exists Methods emptyForall :: forall (a0 :: k0). Const a a0 Source # | |
MonoidForall f => MonoidForall (ApplyForall f :: k -> Type) Source # | |
Defined in Data.Exists Methods emptyForall :: forall (a :: k0). ApplyForall f a Source # |
class SemigroupForeach f => MonoidForeach f where Source #
Methods
emptyForeach :: Sing a -> f a Source #
Instances
MonoidForeach f => MonoidForeach (ApplyForeach f :: k -> Type) Source # | |
Defined in Data.Exists Methods emptyForeach :: forall (a :: k0). Sing a -> ApplyForeach f a Source # |
class HashableForall f where Source #
Methods
hashWithSaltForall :: Int -> f a -> Int Source #
Instances
Hashable a => HashableForall (Const a :: k -> Type) Source # | |
Defined in Data.Exists |
class HashableForeach f where Source #
class PathPieceExists f where Source #
class StorableForeach (f :: k -> Type) where Source #
class StorableForall (f :: k -> Type) where Source #
This is like StorableForall
except that the type constructor
must ignore its argument (for purposes of representation).
Methods
peekForall :: Ptr (f a) -> IO (f a) Source #
pokeForall :: Ptr (f a) -> f a -> IO () Source #
sizeOfForall :: Proxy f -> Int Source #
class PrimForall (f :: k -> Type) where Source #
Be careful with this typeclass. It is more unsafe than Prim
.
With writeByteArray#
and readByteArray#
, one can implement
unsafeCoerce
.
Methods
sizeOfForall# :: Proxy# f -> Int# Source #
alignmentForall# :: Proxy# f -> Int# Source #
indexByteArrayForall# :: ByteArray# -> Int# -> f a Source #
readByteArrayForall# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, f a #) Source #
writeByteArrayForall# :: MutableByteArray# s -> Int# -> f a -> State# s -> State# s Source #
setByteArrayForall# :: MutableByteArray# s -> Int# -> Int# -> f a -> State# s -> State# s Source #
indexOffAddrForall# :: Addr# -> Int# -> f a Source #
readOffAddrForall# :: Addr# -> Int# -> State# s -> (# State# s, f a #) Source #
writeOffAddrForall# :: Addr# -> Int# -> f a -> State# s -> State# s Source #
setOffAddrForall# :: Addr# -> Int# -> Int# -> f a -> State# s -> State# s Source #
class BinaryExists (f :: k -> Type) where Source #
class BinaryForeach (f :: k -> Type) where Source #
Instances
(Binary1 f, BinaryForeach g) => BinaryForeach (Compose f g :: k -> Type) Source # | |
Defined in Data.Exists |
Higher Rank Classes
class EqForallPoly2 (f :: k -> j -> Type) where Source #
Methods
eqForallPoly2 :: forall (a :: k) (b :: j) (c :: k) (d :: j). f a b -> f c d -> WitnessedEquality '(a, b) '(c, d) Source #
class ShowForall2 f where Source #
Methods
showsPrecForall2 :: Int -> f a b -> ShowS Source #
class ShowForeach2 f where Source #
class BinaryExists2 (f :: k -> j -> Type) where Source #
More Type Classes
data SingList :: forall (k :: Type). [k] -> Type where Source #
Constructors
SingListNil :: SingList '[] | |
SingListCons :: Sing r -> SingList rs -> SingList (r ': rs) |
Instances
(SingKind k, Binary k) => BinaryExists (SingList :: [k] -> Type) Source # | |
EqForall (SingList :: [k] -> Type) Source # | |
EqSing k => EqForallPoly (SingList :: [k] -> Type) Source # | |
Defined in Data.Exists Methods eqForallPoly :: forall (a :: k0) (b :: k0). SingList a -> SingList b -> WitnessedEquality a b Source # | |
ShowSing k => Show (SingList xs) Source # | |
data SingMaybe :: Maybe k -> Type where Source #
Constructors
SingMaybeJust :: Sing a -> SingMaybe ('Just a) | |
SingMaybeNothing :: SingMaybe 'Nothing |
Sing Type Classes
class EqSing k => OrdSing k where Source #
Methods
compareSing :: forall (a :: k) (b :: k). Sing a -> Sing b -> WitnessedOrdering a b Source #
class SingKind k where Source #
The two functions must form an isomorphism.
Methods
demoteSing :: Sing (a :: k) -> k Source #
Instances
SingKind k => SingKind [k] Source # | |
Defined in Data.Exists Methods demoteSing :: forall (a :: [k]). Sing a -> [k] Source # promoteSing :: [k] -> Exists Sing Source # |
Functions
Show
showsForall :: ShowForall f => f a -> ShowS Source #
showsForeach :: ShowForeach f => Sing a -> f a -> ShowS Source #
showForall :: ShowForall f => f a -> String Source #
showListForall :: ShowForall f => [f a] -> ShowS Source #
showListForeach :: ShowForeach f => Sing a -> [f a] -> ShowS Source #
showsForall2 :: ShowForall2 f => f a b -> ShowS Source #
showForall2 :: ShowForall2 f => f a b -> String Source #
Defaulting
defaultEqForallPoly :: (TestEquality f, EqForall f) => f a -> f b -> WitnessedEquality a b Source #
defaultCompareForallPoly :: (TestEquality f, OrdForall f) => f a -> f b -> Ordering Source #
Weakening
weakenEquality :: WitnessedEquality a b -> Bool Source #
weakenOrdering :: WitnessedOrdering a b -> Ordering Source #
strengthenEquality :: Bool -> WitnessedEquality a a Source #
strengthenOrdering :: Ordering -> WitnessedOrdering a a Source #
Given that we already know two types are equal, promote an Ordering
.
strengthenUnequalOrdering :: Ordering -> WitnessedOrdering a b Source #
Given that we already know two types to be unequal, promote an Ordering
.
The argument should not be EQ
.