| Copyright | (c) Justin Le 2018 |
|---|---|
| License | BSD3 |
| Maintainer | justin@jle.im |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Type.Universe
Contents
Description
Combinators for working with type-level predicates, along with typeclasses for canonical proofs and deciding functions.
Synopsis
- type family Elem (f :: Type -> Type) :: f k -> k -> Type
- type In (f :: Type -> Type) (as :: f k) = ElemSym1 f as
- class Universe (f :: Type -> Type) where
- data Index :: [k] -> k -> Type where
- data IJust :: Maybe k -> k -> Type where
- data IRight :: Either j k -> k -> Type where
- data NEIndex :: NonEmpty k -> k -> Type where
- data ISnd :: (j, k) -> k -> Type where
- data CompElem :: (f :.: g) k -> k -> Type where
- data All f :: (k ~> Type) -> f k ~> Type
- newtype WitAll f p (as :: f k) = WitAll {}
- type NotAll f p = (Not (All f p) :: Predicate (f k))
- data Any f :: (k ~> Type) -> f k ~> Type
- data WitAny f :: (k ~> Type) -> f k -> Type where
- type None f p = (Not (Any f p) :: Predicate (f k))
- type Null f = (None f Evident :: Predicate (f k))
- type NotNull f = (Any f Evident :: Predicate (f k))
- type IsJust = (NotNull Maybe :: Predicate (Maybe k))
- type IsNothing = (Null Maybe :: Predicate (Maybe k))
- type IsRight = (NotNull (Either j) :: Predicate (Either j k))
- type IsLeft = (Null (Either j) :: Predicate (Either j k))
- decideAny :: forall f k (p :: k ~> Type). Universe f => Decide p -> Decide (Any f p)
- decideAll :: forall f k (p :: k ~> Type). Universe f => Decide p -> Decide (All f p)
- genAllA :: forall f k (p :: k ~> Type) (as :: f k) h. (Universe f, Applicative h) => (forall a. Sing a -> h (p @@ a)) -> Sing as -> h (All f p @@ as)
- genAll :: forall f k (p :: k ~> Type). Universe f => Prove p -> Prove (All f p)
- igenAll :: forall f k (p :: k ~> Type) (as :: f k). Universe f => (forall a. Elem f as a -> Sing a -> p @@ a) -> Sing as -> All f p @@ as
- foldMapUni :: forall f k (as :: f k) m. (Universe f, Monoid m) => (forall (a :: k). Sing a -> m) -> Sing as -> m
- ifoldMapUni :: forall f k (as :: f k) m. (Universe f, Monoid m) => (forall a. Elem f as a -> Sing a -> m) -> Sing as -> m
- index :: forall f as a. Universe f => Elem f as a -> Sing as -> Sing a
- pickElem :: forall f k (as :: f k) a. (Universe f, SingI as, SingI a, SDecide k) => Decision (Elem f as a)
- data (f :.: g) a = Comp {
- getComp :: f (g a)
- data family Sing (a :: k) :: *
- sGetComp :: Sing a -> Sing (GetComp a)
- type family GetComp c where ...
- allComp :: (All f (All g p) @@ as) -> All (f :.: g) p @@ Comp as
- compAll :: (All (f :.: g) p @@ Comp as) -> All f (All g p) @@ as
- anyComp :: (Any f (Any g p) @@ as) -> Any (f :.: g) p @@ Comp as
- compAny :: (Any (f :.: g) p @@ Comp as) -> Any f (Any g p) @@ as
- data ElemSym0 (f :: Type -> Type) :: f k ~> (k ~> Type)
- data ElemSym1 (f :: Type -> Type) :: f k -> k ~> Type
- type ElemSym2 (f :: Type -> Type) (as :: f k) (a :: k) = Elem f as a
- data GetCompSym0 :: (f :.: g) k ~> f (g k)
- type GetCompSym1 a = GetComp a
Universe
type family Elem (f :: Type -> Type) :: f k -> k -> Type Source #
A witness for membership of a given item in a type-level collection
type In (f :: Type -> Type) (as :: f k) = ElemSym1 f as Source #
is a predicate that a given input In f asa is a member of
collection as.
class Universe (f :: Type -> Type) where Source #
Typeclass for a type-level container that you can quantify or lift type-level predicates over.
Minimal complete definition
Methods
Arguments
| :: forall (p :: k ~> Type) (as :: f k). (forall a. Elem f as a -> Sing a -> Decision (p @@ a)) | predicate on value |
| -> Sing as -> Decision (Any f p @@ as) | predicate on collection |
Arguments
| :: forall (p :: k ~> Type) (as :: f k). (forall a. Elem f as a -> Sing a -> Decision (p @@ a)) | predicate on value |
| -> Sing as -> Decision (All f p @@ as) | predicate on collection |
Instances
| Universe [] Source # | |
Defined in Data.Type.Universe Methods idecideAny :: (forall (a :: k). Elem [] as a -> Sing a -> Decision (p @@ a)) -> Sing as -> Decision (Any [] p @@ as) Source # idecideAll :: (forall (a :: k). Elem [] as a -> Sing a -> Decision (p @@ a)) -> Sing as -> Decision (All [] p @@ as) Source # igenAllA :: Applicative h => (forall (a :: k). Elem [] as a -> Sing a -> h (p @@ a)) -> Sing as -> h (All [] p @@ as) Source # | |
| Universe Maybe Source # | |
Defined in Data.Type.Universe Methods idecideAny :: (forall (a :: k). Elem Maybe as a -> Sing a -> Decision (p @@ a)) -> Sing as -> Decision (Any Maybe p @@ as) Source # idecideAll :: (forall (a :: k). Elem Maybe as a -> Sing a -> Decision (p @@ a)) -> Sing as -> Decision (All Maybe p @@ as) Source # igenAllA :: Applicative h => (forall (a :: k). Elem Maybe as a -> Sing a -> h (p @@ a)) -> Sing as -> h (All Maybe p @@ as) Source # | |
| Universe NonEmpty Source # | |
Defined in Data.Type.Universe Methods idecideAny :: (forall (a :: k). Elem NonEmpty as a -> Sing a -> Decision (p @@ a)) -> Sing as -> Decision (Any NonEmpty p @@ as) Source # idecideAll :: (forall (a :: k). Elem NonEmpty as a -> Sing a -> Decision (p @@ a)) -> Sing as -> Decision (All NonEmpty p @@ as) Source # igenAllA :: Applicative h => (forall (a :: k). Elem NonEmpty as a -> Sing a -> h (p @@ a)) -> Sing as -> h (All NonEmpty p @@ as) Source # | |
| Universe (Either j) Source # | |
Defined in Data.Type.Universe Methods idecideAny :: (forall (a :: k). Elem (Either j) as a -> Sing a -> Decision (p @@ a)) -> Sing as -> Decision (Any (Either j) p @@ as) Source # idecideAll :: (forall (a :: k). Elem (Either j) as a -> Sing a -> Decision (p @@ a)) -> Sing as -> Decision (All (Either j) p @@ as) Source # igenAllA :: Applicative h => (forall (a :: k). Elem (Either j) as a -> Sing a -> h (p @@ a)) -> Sing as -> h (All (Either j) p @@ as) Source # | |
| Universe ((,) j) Source # | |
Defined in Data.Type.Universe Methods idecideAny :: (forall (a :: k). Elem ((,) j) as a -> Sing a -> Decision (p @@ a)) -> Sing as -> Decision (Any ((,) j) p @@ as) Source # idecideAll :: (forall (a :: k). Elem ((,) j) as a -> Sing a -> Decision (p @@ a)) -> Sing as -> Decision (All ((,) j) p @@ as) Source # igenAllA :: Applicative h => (forall (a :: k). Elem ((,) j) as a -> Sing a -> h (p @@ a)) -> Sing as -> h (All ((,) j) p @@ as) Source # | |
| (Universe f, Universe g) => Universe (f :.: g) Source # | |
Defined in Data.Type.Universe Methods idecideAny :: (forall (a :: k). Elem (f :.: g) as a -> Sing a -> Decision (p @@ a)) -> Sing as -> Decision (Any (f :.: g) p @@ as) Source # idecideAll :: (forall (a :: k). Elem (f :.: g) as a -> Sing a -> Decision (p @@ a)) -> Sing as -> Decision (All (f :.: g) p @@ as) Source # igenAllA :: Applicative h => (forall (a :: k). Elem (f :.: g) as a -> Sing a -> h (p @@ a)) -> Sing as -> h (All (f :.: g) p @@ as) Source # | |
Instances
data Index :: [k] -> k -> Type where Source #
Witness an item in a type-level list by providing its index.
data NEIndex :: NonEmpty k -> k -> Type where Source #
Witness an item in a type-level NonEmpty by either indicating that
it is the "head", or by providing an index in the "tail".
data ISnd :: (j, k) -> k -> Type where Source #
Trivially witness an item in the second field of a type-level tuple.
data CompElem :: (f :.: g) k -> k -> Type where Source #
A pair of indices allows you to index into a nested structure.
Since: decidable-0.1.2.0
Predicates
data All f :: (k ~> Type) -> f k ~> Type Source #
An is a predicate testing a collection All f pas :: f a for the
fact that all items in as satisfy p. Represents the "forall"
quantifier over a given universe.
This is mostly useful for its Decidable, Provable, and TFunctor
instances, which lets you lift predicates on p to predicates on .All
f p
Instances
| Universe f => TFunctor (All f :: (k1 ~> Type) -> TyFun (f k1) Type -> *) Source # | |
| Universe f => DFunctor (All f :: (k1 ~> Type) -> TyFun (f k1) Type -> *) Source # | |
| (Universe f, Provable p) => Provable (All f p :: TyFun (f k) Type -> *) Source # | |
| (Universe f, Decidable p) => Decidable (All f p :: TyFun (f k) Type -> *) Source # | |
| AutoAll f p as => Auto (All f p :: TyFun (f k) Type -> *) (as :: f k) Source # | Since: decidable-0.1.2.0 |
| type Apply (All f p :: TyFun (f k) Type -> *) (as :: f k) Source # | |
newtype WitAll f p (as :: f k) Source #
A is a witness that the predicate WitAll p asp a is true for all
items a in the type-level collection as.
type NotAll f p = (Not (All f p) :: Predicate (f k)) Source #
A is a predicate on a collection NotAll f pas that at least one
a in as does not satisfy predicate p.
data Any f :: (k ~> Type) -> f k ~> Type Source #
An is a predicate testing a collection Any f pas :: f a for the
fact that at least one item in as satisfies p. Represents the
"exists" quantifier over a given universe.
This is mostly useful for its Decidable and TFunctor instances,
which lets you lift predicates on p to predicates on .Any f p
Instances
| Universe f => TFunctor (Any f :: (k1 ~> Type) -> TyFun (f k1) Type -> *) Source # | |
| SingI a => Auto (IsJust :: Predicate (Maybe k)) (Just a :: Maybe k) Source # | Since: decidable-0.1.2.0 |
| (SingI as, AutoAll f (Not p) as) => Auto (Not (Any f p) :: TyFun (f k) Type -> *) (as :: f k) Source # | Since: decidable-0.1.2.0 |
| SingI a => Auto (NotNull [] :: Predicate [k]) (a ': as :: [k]) Source # | Since: decidable-0.1.2.0 |
| SingI a => Auto (NotNull NonEmpty :: Predicate (NonEmpty k)) (a :| as :: NonEmpty k) Source # | Since: decidable-0.1.2.0 |
| Provable p => Provable ((NotNull f :: Predicate (f k)) ==> Any f p :: TyFun (f k) Type -> *) Source # | |
| Provable (Found (InP f :: ParamPred (f v) v) ==> (NotNull f :: Predicate (f v)) :: TyFun (f v) Type -> *) Source # | |
| Provable ((NotNull f :: Predicate (f k)) ==> Found (InP f :: ParamPred (f k) k) :: TyFun (f k) Type -> *) Source # | |
| (Universe f, Provable p) => Decidable ((NotNull f :: Predicate (f k)) ==> Any f p :: TyFun (f k) Type -> *) Source # | |
| (Universe f, Decidable p) => Decidable (Any f p :: TyFun (f k) Type -> *) Source # | |
| Decidable (Found (InP f :: ParamPred (f v) v) ==> (NotNull f :: Predicate (f v)) :: TyFun (f v) Type -> *) Source # | |
| Decidable ((NotNull f :: Predicate (f k)) ==> Found (InP f :: ParamPred (f k) k) :: TyFun (f k) Type -> *) Source # | |
| SingI a => Auto (IsRight :: Predicate (Either j k)) (Right a :: Either j k) Source # | Since: decidable-0.1.2.0 |
| SingI a => Auto (NotNull ((,) j) :: Predicate (j, k)) ((,) w a :: (j, k)) Source # | Since: decidable-0.1.2.0 |
| type Apply (Any f p :: TyFun (f k) Type -> *) (as :: f k) Source # | |
data WitAny f :: (k ~> Type) -> f k -> Type where Source #
A is a witness that, for at least one item WitAny p asa in the
type-level collection as, the predicate p a is true.
type None f p = (Not (Any f p) :: Predicate (f k)) Source #
A is a predicate on a collection None f pas that no a in as
satisfies predicate p.
type Null f = (None f Evident :: Predicate (f k)) Source #
Predicate that a given as :: f k is empty and has no items in it.
type NotNull f = (Any f Evident :: Predicate (f k)) Source #
Predicate that a given as :: f k is not empty, and has at least one
item in it.
Specialized
Decisions and manipulations
Arguments
| :: forall (p :: k ~> Type). Universe f | |
| => Decide p | predicate on value |
| -> Decide (Any f p) | predicate on collection |
Lifts a predicate p on an individual a into a predicate that on
a collection as that is true if and only if any item in as
satisfies the original predicate.
That is, it turns a predicate of kind k ~> Type into a predicate
of kind f k ~> Type.
Essentially tests existential quantification.
Arguments
| :: forall (p :: k ~> Type). Universe f | |
| => Decide p | predicate on value |
| -> Decide (All f p) | predicate on collection |
Lifts a predicate p on an individual a into a predicate that on
a collection as that is true if and only if all items in as
satisfies the original predicate.
That is, it turns a predicate of kind k ~> Type into a predicate
of kind f k ~> Type.
Essentially tests universal quantification.
Arguments
| :: forall (p :: k ~> Type) (as :: f k). (Universe f, Applicative h) | |
| => (forall a. Sing a -> h (p @@ a)) | predicate on value in context |
| -> Sing as -> h (All f p @@ as) | predicate on collection in context |
If p a is true for all values a in as under some
(Applicative) context h, then you can create an under
that Applicative context All p ash.
Can be useful with Identity (which is basically unwrapping and
wrapping All), or with Maybe (which can express predicates that
are either provably true or not provably false).
In practice, this can be used to iterate and traverse and sequence
actions over all "items" in as.
foldMapUni :: forall f k (as :: f k) m. (Universe f, Monoid m) => (forall (a :: k). Sing a -> m) -> Sing as -> m Source #
A foldMap over all items in a collection.
ifoldMapUni :: forall f k (as :: f k) m. (Universe f, Monoid m) => (forall a. Elem f as a -> Sing a -> m) -> Sing as -> m Source #
foldMapUni but with access to the index.
Extract the item from the container witnessed by the Elem
pickElem :: forall f k (as :: f k) a. (Universe f, SingI as, SingI a, SDecide k) => Decision (Elem f as a) Source #
Automatically generate a witness for a member, if possible
Universe Composition
Compose two Functors. Is the same as Compose
and :.:, except with a singleton and meant to be used at
the type level. Will be redundant if either of the above gets brought
into the singletons library.
Note that because this is a higher-kinded data constructor, there is no
SingKind instance; if you need fromSing and toSing, try going
through Comp and getComp and SComp and sGetComp.
Since: decidable-0.1.2.0
Instances
| AutoAll f (All g p) ass => AutoAll (f :.: g) (p :: a ~> Type) (Comp ass :: (f :.: g) a) Source # | |
| (Functor f, Functor g) => Functor (f :.: g) Source # | |
| (Foldable f, Foldable g) => Foldable (f :.: g) Source # | |
Defined in Data.Type.Universe Methods fold :: Monoid m => (f :.: g) m -> m # foldMap :: Monoid m => (a -> m) -> (f :.: g) a -> m # foldr :: (a -> b -> b) -> b -> (f :.: g) a -> b # foldr' :: (a -> b -> b) -> b -> (f :.: g) a -> b # foldl :: (b -> a -> b) -> b -> (f :.: g) a -> b # foldl' :: (b -> a -> b) -> b -> (f :.: g) a -> b # foldr1 :: (a -> a -> a) -> (f :.: g) a -> a # foldl1 :: (a -> a -> a) -> (f :.: g) a -> a # toList :: (f :.: g) a -> [a] # length :: (f :.: g) a -> Int # elem :: Eq a => a -> (f :.: g) a -> Bool # maximum :: Ord a => (f :.: g) a -> a # minimum :: Ord a => (f :.: g) a -> a # | |
| (Traversable f, Traversable g) => Traversable (f :.: g) Source # | |
Defined in Data.Type.Universe | |
| (Universe f, Universe g) => Universe (f :.: g) Source # | |
Defined in Data.Type.Universe Methods idecideAny :: (forall (a :: k). Elem (f :.: g) as a -> Sing a -> Decision (p @@ a)) -> Sing as -> Decision (Any (f :.: g) p @@ as) Source # idecideAll :: (forall (a :: k). Elem (f :.: g) as a -> Sing a -> Decision (p @@ a)) -> Sing as -> Decision (All (f :.: g) p @@ as) Source # igenAllA :: Applicative h => (forall (a :: k). Elem (f :.: g) as a -> Sing a -> h (p @@ a)) -> Sing as -> h (All (f :.: g) p @@ as) Source # | |
| Eq (f (g a)) => Eq ((f :.: g) a) Source # | |
| Ord (f (g a)) => Ord ((f :.: g) a) Source # | |
Defined in Data.Type.Universe | |
| Show (f (g a)) => Show ((f :.: g) a) Source # | |
| Generic ((f :.: g) a) Source # | |
| SingI ass => SingI (Comp ass :: (f :.: g) a) Source # | |
Defined in Data.Type.Universe | |
| type Elem (f :.: g) Source # | |
| type Rep ((f :.: g) a) Source # | |
Defined in Data.Type.Universe | |
| data Sing (k :: (f :.: g) a) Source # | |
| type Apply (GetCompSym0 :: TyFun ((f :.: g) k3) (f (g k3)) -> *) (Comp ass :: (f :.: g) k3) Source # | |
Defined in Data.Type.Universe | |
data family Sing (a :: k) :: * #
The singleton kind-indexed data family.
Instances
sGetComp :: Sing a -> Sing (GetComp a) Source #
Singletonized witness for GetComp
Since: decidable-0.1.2.0
Defunctionalization symbols
data ElemSym1 (f :: Type -> Type) :: f k -> k ~> Type Source #
Instances
| AutoElem f as a => Auto (In f as :: TyFun k Type -> *) (a :: k) Source # | |
| Provable (Found (InP f :: ParamPred (f v) v) ==> (NotNull f :: Predicate (f v)) :: TyFun (f v) Type -> *) Source # | |
| Provable ((NotNull f :: Predicate (f k)) ==> Found (InP f :: ParamPred (f k) k) :: TyFun (f k) Type -> *) Source # | |
| Decidable (Found (InP f :: ParamPred (f v) v) ==> (NotNull f :: Predicate (f v)) :: TyFun (f v) Type -> *) Source # | |
| Decidable ((NotNull f :: Predicate (f k)) ==> Found (InP f :: ParamPred (f k) k) :: TyFun (f k) Type -> *) Source # | |
| Universe f => Decidable (Found (InP f :: ParamPred (f v) v) :: TyFun (f v) Type -> *) Source # | |
| type Apply (ElemSym1 f as :: TyFun k Type -> *) (a :: k) Source # | |
data GetCompSym0 :: (f :.: g) k ~> f (g k) Source #
type GetCompSym1 a = GetComp a Source #