| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Functor.Polynomial.Tag
Description
Synopsis
- class HasFinitary (tag :: Type -> Type) where
- withFinitary :: tag n -> (Finitary n => r) -> r
- data TagMaybe n where
- TagNothing :: TagMaybe Void
- TagJust :: TagMaybe ()
- data TagList a where
- type TagFn = (:~:) :: k -> k -> Type
- data TagV n
- data TagK c n where
- type TagSum = (:+:) :: (k -> Type) -> (k -> Type) -> k -> Type
- data TagMul (f :: Type -> Type) (g :: Type -> Type) x where
- data TagPow (n :: Natural) (t :: Type -> Type) xs where
- geqPow :: forall (t :: Type -> Type) (n :: Natural) xs (n' :: Natural) xs'. GEq t => TagPow n t xs -> TagPow n' t xs' -> Maybe (n :~: n', xs :~: xs')
- gcomparePow :: forall (t :: Type -> Type) (n :: Natural) xs (n' :: Natural) xs'. GCompare t => TagPow n t xs -> TagPow n' t xs' -> GOrdering '(n, xs) '(n', xs')
- data TagComp (t :: Type -> Type) (u :: Type -> Type) n where
- data TagDay (t :: Type -> Type) (u :: Type -> Type) n where
- class GShow (t :: k -> Type) where
- gshowsPrec :: forall (a :: k). Int -> t a -> ShowS
- class GEq (f :: k -> Type) where
- class GEq f => GCompare (f :: k -> Type) where
- data GOrdering (a :: k) (b :: k) where
The type class for tags
class HasFinitary (tag :: Type -> Type) where Source #
Methods
withFinitary :: tag n -> (Finitary n => r) -> r Source #
Instances
Tags
data TagMaybe n where Source #
Tag of Maybe.
Constructors
| TagNothing :: TagMaybe Void | |
| TagJust :: TagMaybe () |
Instances
| HasFinitary TagMaybe Source # | |
Defined in Data.Functor.Polynomial.Tag Methods withFinitary :: TagMaybe n -> (Finitary n => r) -> r Source # | |
| GCompare TagMaybe Source # | |
| GEq TagMaybe Source # | |
| GShow TagMaybe Source # | |
Defined in Data.Functor.Polynomial.Tag Methods gshowsPrec :: Int -> TagMaybe a -> ShowS # | |
| Show (TagMaybe n) Source # | |
| Eq (TagMaybe n) Source # | |
| Ord (TagMaybe n) Source # | |
Defined in Data.Functor.Polynomial.Tag | |
Instances
| HasFinitary TagList Source # | |
Defined in Data.Functor.Polynomial.Tag Methods withFinitary :: TagList n -> (Finitary n => r) -> r Source # | |
| GCompare TagList Source # | |
| GEq TagList Source # | |
| GShow TagList Source # | |
Defined in Data.Functor.Polynomial.Tag Methods gshowsPrec :: Int -> TagList a -> ShowS # | |
| Show (TagList a) Source # | |
| Eq (TagList a) Source # | |
| Ord (TagList a) Source # | |
TagV n is an empty type for any n. It represents (∅, α = absurd :: ∅ -> Nat).
This is the tag of V1.
Instances
| HasFinitary TagV Source # | |
Defined in Data.Functor.Polynomial.Tag Methods withFinitary :: TagV n -> (Finitary n => r) -> r Source # | |
| GCompare TagV Source # | |
| GEq TagV Source # | |
| GShow TagV Source # | |
Defined in Data.Functor.Polynomial.Tag Methods gshowsPrec :: Int -> TagV a -> ShowS # | |
| Show (TagV n) Source # | |
| Eq (TagV n) Source # | |
| Ord (TagV n) Source # | |
TagK c n represents (c, α), where α is a constant function to Void:
α = const Void :: c -> Type
This is the tag of Const.
Instances
| Ord c => GCompare (TagK c :: Type -> Type) Source # | |
| Eq c => GEq (TagK c :: Type -> Type) Source # | |
| Show c => GShow (TagK c :: Type -> Type) Source # | |
Defined in Data.Functor.Polynomial.Tag Methods gshowsPrec :: Int -> TagK c a -> ShowS # | |
| HasFinitary (TagK c) Source # | |
Defined in Data.Functor.Polynomial.Tag Methods withFinitary :: TagK c n -> (Finitary n => r) -> r Source # | |
| Show c => Show (TagK c n) Source # | |
| Eq c => Eq (TagK c n) Source # | |
| Ord c => Ord (TagK c n) Source # | |
Defined in Data.Functor.Polynomial.Tag | |
type TagSum = (:+:) :: (k -> Type) -> (k -> Type) -> k -> Type Source #
When t1, t2 represents (U, α1) and (V,α2) respectively,
α1 :: U -> Nat α2 :: V -> Nat
TagSum t1 t2 represents (Either U V, β = either α1 α2).
β :: Either U V -> Nat β (Left u) = α1(u) β (Right v) = α2(v)
This is the tag of f :+: g, when t1, t2 is the tag of f, g respectively.
data TagMul (f :: Type -> Type) (g :: Type -> Type) x where Source #
When t1, t2 represents (U, α1) and (V,α2) respectively,
α1 :: U -> Nat α2 :: V -> Nat
TagMul t1 t2 represents the direct product (U,V) and the function β on it:
β :: (U,V) -> Nat β(u,v) = α1 u + α2 v
This is the tag of f :*: g when t1, t2 is the tag of f, g respectively.
Constructors
| TagMul :: forall (f :: Type -> Type) x1 (g :: Type -> Type) y. !(f x1) -> !(g y) -> TagMul f g (Either x1 y) |
Instances
| (GCompare t1, GCompare t2) => GCompare (TagMul t1 t2 :: Type -> Type) Source # | |
| (GEq t1, GEq t2) => GEq (TagMul t1 t2 :: Type -> Type) Source # | |
| (forall n. Show (t1 n), forall n. Show (t2 n)) => GShow (TagMul t1 t2 :: Type -> Type) Source # | |
Defined in Data.Functor.Polynomial.Tag Methods gshowsPrec :: Int -> TagMul t1 t2 a -> ShowS # | |
| (HasFinitary t1, HasFinitary t2) => HasFinitary (TagMul t1 t2) Source # | |
Defined in Data.Functor.Polynomial.Tag Methods withFinitary :: TagMul t1 t2 n -> (Finitary n => r) -> r Source # | |
| (forall n. Show (t1 n), forall n. Show (t2 n)) => Show (TagMul t1 t2 m) Source # | |
| (GEq t1, GEq t2) => Eq (TagMul t1 t2 n) Source # | |
| (GCompare t1, GCompare t2) => Ord (TagMul t1 t2 n) Source # | |
Defined in Data.Functor.Polynomial.Tag Methods compare :: TagMul t1 t2 n -> TagMul t1 t2 n -> Ordering # (<) :: TagMul t1 t2 n -> TagMul t1 t2 n -> Bool # (<=) :: TagMul t1 t2 n -> TagMul t1 t2 n -> Bool # (>) :: TagMul t1 t2 n -> TagMul t1 t2 n -> Bool # (>=) :: TagMul t1 t2 n -> TagMul t1 t2 n -> Bool # | |
data TagPow (n :: Natural) (t :: Type -> Type) xs where Source #
When t represents (U,α :: U -> Type),
TagPow n t xs represents α^n below:
α^n :: U^n -> Type α^n(u1, u2, ..., u_n) = α u1 + α u2 + ... + α u_n
This is the tag of when Pow n ft is the tag of f.
Constructors
| TagPow0 :: forall (t :: Type -> Type). TagPow 0 t Void | |
| TagPowNZ :: forall (n :: Natural) (t :: Type -> Type) xs. TagPow' n t xs -> TagPow n t xs |
Instances
| GCompare t => GCompare (TagPow n t :: Type -> Type) Source # | |
| GEq t => GEq (TagPow n t :: Type -> Type) Source # | |
| (forall n. Show (t n)) => GShow (TagPow m t :: Type -> Type) Source # | |
Defined in Data.Functor.Pow Methods gshowsPrec :: Int -> TagPow m t a -> ShowS # | |
| HasFinitary t => HasFinitary (TagPow n t) Source # | |
Defined in Data.Functor.Pow Methods withFinitary :: TagPow n t n0 -> (Finitary n0 => r) -> r Source # | |
| (forall n. Show (t n)) => Show (TagPow m t xs) Source # | |
| GEq t => Eq (TagPow n t xs) Source # | |
| GCompare t => Ord (TagPow n t xs) Source # | |
Defined in Data.Functor.Pow Methods compare :: TagPow n t xs -> TagPow n t xs -> Ordering # (<) :: TagPow n t xs -> TagPow n t xs -> Bool # (<=) :: TagPow n t xs -> TagPow n t xs -> Bool # (>) :: TagPow n t xs -> TagPow n t xs -> Bool # (>=) :: TagPow n t xs -> TagPow n t xs -> Bool # | |
geqPow :: forall (t :: Type -> Type) (n :: Natural) xs (n' :: Natural) xs'. GEq t => TagPow n t xs -> TagPow n' t xs' -> Maybe (n :~: n', xs :~: xs') Source #
gcomparePow :: forall (t :: Type -> Type) (n :: Natural) xs (n' :: Natural) xs'. GCompare t => TagPow n t xs -> TagPow n' t xs' -> GOrdering '(n, xs) '(n', xs') Source #
data TagComp (t :: Type -> Type) (u :: Type -> Type) n where Source #
When t, u is the tag of f, g respectively,
TagComp t u is the tag of f :.: g.
Constructors
| TagComp :: forall (t :: Type -> Type) a (u :: Type -> Type) n. t a -> TagPow (Cardinality a) u n -> TagComp t u n |
Instances
| (GCompare t, GCompare u) => GCompare (TagComp t u :: Type -> Type) Source # | |
| (GEq t, GEq u) => GEq (TagComp t u :: Type -> Type) Source # | |
| (forall n. Show (t n), forall n. Show (u n)) => GShow (TagComp t u :: Type -> Type) Source # | |
Defined in Data.Functor.Polynomial.Tag Methods gshowsPrec :: Int -> TagComp t u a -> ShowS # | |
| HasFinitary u => HasFinitary (TagComp t u) Source # | |
Defined in Data.Functor.Polynomial.Tag Methods withFinitary :: TagComp t u n -> (Finitary n => r) -> r Source # | |
| (forall n. Show (t n), forall n. Show (u n)) => Show (TagComp t u m) Source # | |
| (GEq t, GEq u) => Eq (TagComp t u n) Source # | |
| (GCompare t, GCompare u) => Ord (TagComp t u n) Source # | |
Defined in Data.Functor.Polynomial.Tag Methods compare :: TagComp t u n -> TagComp t u n -> Ordering # (<) :: TagComp t u n -> TagComp t u n -> Bool # (<=) :: TagComp t u n -> TagComp t u n -> Bool # (>) :: TagComp t u n -> TagComp t u n -> Bool # (>=) :: TagComp t u n -> TagComp t u n -> Bool # | |
data TagDay (t :: Type -> Type) (u :: Type -> Type) n where Source #
Constructors
| TagDay :: forall (t :: Type -> Type) n1 (u :: Type -> Type) m. t n1 -> u m -> TagDay t u (n1, m) |
Instances
| (GCompare t, GCompare u) => GCompare (TagDay t u :: Type -> Type) Source # | |
| (GEq t, GEq u) => GEq (TagDay t u :: Type -> Type) Source # | |
| (forall n. Show (t n), forall n. Show (u n)) => GShow (TagDay t u :: Type -> Type) Source # | |
Defined in Data.Functor.Polynomial.Tag Methods gshowsPrec :: Int -> TagDay t u a -> ShowS # | |
| (HasFinitary t, HasFinitary u) => HasFinitary (TagDay t u) Source # | |
Defined in Data.Functor.Polynomial.Tag Methods withFinitary :: TagDay t u n -> (Finitary n => r) -> r Source # | |
| (forall n. Show (t n), forall n. Show (u n)) => Show (TagDay t u m) Source # | |
| (GEq t, GEq u) => Eq (TagDay t u n) Source # | |
| (GCompare t, GCompare u) => Ord (TagDay t u m) Source # | |
Defined in Data.Functor.Polynomial.Tag | |
Reexports
class GShow (t :: k -> Type) where #
Show-like class for 1-type-parameter GADTs. GShow t => ... is equivalent to something
like (forall a. Show (t a)) => .... The easiest way to create instances would probably be
to write (or derive) an instance Show (T a), and then simply say:
instance GShow t where gshowsPrec = defaultGshowsPrec
Methods
gshowsPrec :: forall (a :: k). Int -> t a -> ShowS #
Instances
| GShow SNat | |
Defined in Data.GADT.Internal | |
| GShow SChar | |
Defined in Data.GADT.Internal | |
| GShow SSymbol | |
Defined in Data.GADT.Internal | |
| GShow TagList Source # | |
Defined in Data.Functor.Polynomial.Tag Methods gshowsPrec :: Int -> TagList a -> ShowS # | |
| GShow TagMaybe Source # | |
Defined in Data.Functor.Polynomial.Tag Methods gshowsPrec :: Int -> TagMaybe a -> ShowS # | |
| GShow TagV Source # | |
Defined in Data.Functor.Polynomial.Tag Methods gshowsPrec :: Int -> TagV a -> ShowS # | |
| Show c => GShow (TagK c :: Type -> Type) Source # | |
Defined in Data.Functor.Polynomial.Tag Methods gshowsPrec :: Int -> TagK c a -> ShowS # | |
| GShow (TypeRep :: k -> Type) | |
Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a :: k). Int -> TypeRep a -> ShowS # | |
| (forall n. Show (t n), forall n. Show (u n)) => GShow (TagComp t u :: Type -> Type) Source # | |
Defined in Data.Functor.Polynomial.Tag Methods gshowsPrec :: Int -> TagComp t u a -> ShowS # | |
| (forall n. Show (t n), forall n. Show (u n)) => GShow (TagDay t u :: Type -> Type) Source # | |
Defined in Data.Functor.Polynomial.Tag Methods gshowsPrec :: Int -> TagDay t u a -> ShowS # | |
| (forall n. Show (t1 n), forall n. Show (t2 n)) => GShow (TagMul t1 t2 :: Type -> Type) Source # | |
Defined in Data.Functor.Polynomial.Tag Methods gshowsPrec :: Int -> TagMul t1 t2 a -> ShowS # | |
| (forall n. Show (t n)) => GShow (TagPow m t :: Type -> Type) Source # | |
Defined in Data.Functor.Pow Methods gshowsPrec :: Int -> TagPow m t a -> ShowS # | |
| (forall m. Show (t m)) => GShow (TagPow' n t :: Type -> Type) Source # | |
Defined in Data.Functor.Pow Methods gshowsPrec :: Int -> TagPow' n t a -> ShowS # | |
| GShow ((:~:) a :: k -> Type) | |
Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a0 :: k). Int -> (a :~: a0) -> ShowS # | |
| GShow (GOrdering a :: k -> Type) | |
Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a0 :: k). Int -> GOrdering a a0 -> ShowS # | |
| (GShow a, GShow b) => GShow (Product a b :: k -> Type) |
|
Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a0 :: k). Int -> Product a b a0 -> ShowS # | |
| (GShow a, GShow b) => GShow (Sum a b :: k -> Type) |
|
Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a0 :: k). Int -> Sum a b a0 -> ShowS # | |
| GShow ((:~~:) a :: k -> Type) | Since: some-1.0.4 |
Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a0 :: k). Int -> (a :~~: a0) -> ShowS # | |
| (GShow a, GShow b) => GShow (a :*: b :: k -> Type) |
Since: some-1.0.4 |
Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a0 :: k). Int -> (a :*: b) a0 -> ShowS # | |
| (GShow a, GShow b) => GShow (a :+: b :: k -> Type) |
Since: some-1.0.4 |
Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a0 :: k). Int -> (a :+: b) a0 -> ShowS # | |
class GEq (f :: k -> Type) where #
A class for type-contexts which contain enough information to (at least in some cases) decide the equality of types occurring within them.
This class is sometimes confused with TestEquality from base.
TestEquality only checks type equality.
Consider
>>>data Tag a where TagInt1 :: Tag Int; TagInt2 :: Tag Int
The correct instance isTestEquality Tag
>>>:{instance TestEquality Tag where testEquality TagInt1 TagInt1 = Just Refl testEquality TagInt1 TagInt2 = Just Refl testEquality TagInt2 TagInt1 = Just Refl testEquality TagInt2 TagInt2 = Just Refl :}
While we can define
instanceGEqTag wheregeq=testEquality
this will mean we probably want to have
instanceEqTag where _==_ = True
Note: In the future version of some package (to be released around GHC-9.6 / 9.8) the
forall a. Eq (f a) constraint will be added as a constraint to GEq,
with a law relating GEq and Eq:
geqx y = Just Refl ⇒ x == y = True ∀ (x :: f a) (y :: f b) x == y ≡ isJust (geqx y) ∀ (x, y :: f a)
So, the more useful instance would differentiate between
different constructors:GEq Tag
>>>:{instance GEq Tag where geq TagInt1 TagInt1 = Just Refl geq TagInt1 TagInt2 = Nothing geq TagInt2 TagInt1 = Nothing geq TagInt2 TagInt2 = Just Refl :}
which is consistent with a derived Eq instance for Tag
>>>deriving instance Eq (Tag a)
Note that even if a ~ b, the may
be geq (x :: f a) (y :: f b)Nothing (when value terms are inequal).
The consistency of GEq and Eq is easy to check by exhaustion:
>>>let checkFwdGEq :: (forall a. Eq (f a), GEq f) => f a -> f b -> Bool; checkFwdGEq x y = case geq x y of Just Refl -> x == y; Nothing -> True>>>(checkFwdGEq TagInt1 TagInt1, checkFwdGEq TagInt1 TagInt2, checkFwdGEq TagInt2 TagInt1, checkFwdGEq TagInt2 TagInt2)(True,True,True,True)
>>>let checkBwdGEq :: (Eq (f a), GEq f) => f a -> f a -> Bool; checkBwdGEq x y = if x == y then isJust (geq x y) else isNothing (geq x y)>>>(checkBwdGEq TagInt1 TagInt1, checkBwdGEq TagInt1 TagInt2, checkBwdGEq TagInt2 TagInt1, checkBwdGEq TagInt2 TagInt2)(True,True,True,True)
Methods
geq :: forall (a :: k) (b :: k). f a -> f b -> Maybe (a :~: b) #
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)
Instances
| GEq SNat | |
| GEq SChar | |
| GEq SSymbol | |
| GEq TagList Source # | |
| GEq TagMaybe Source # | |
| GEq TagV Source # | |
| Eq c => GEq (TagK c :: Type -> Type) Source # | |
| GEq (TypeRep :: k -> Type) | |
| (GEq t, GEq u) => GEq (TagComp t u :: Type -> Type) Source # | |
| (GEq t, GEq u) => GEq (TagDay t u :: Type -> Type) Source # | |
| (GEq t1, GEq t2) => GEq (TagMul t1 t2 :: Type -> Type) Source # | |
| GEq t => GEq (TagPow n t :: Type -> Type) Source # | |
| GEq t => GEq (TagPow' n t :: Type -> Type) Source # | |
| GEq ((:~:) a :: k -> Type) | |
| (GEq a, GEq b) => GEq (Product a b :: k -> Type) | |
| (GEq a, GEq b) => GEq (Sum a b :: k -> Type) | |
| GEq ((:~~:) a :: k -> Type) | Since: some-1.0.4 |
| (GEq a, GEq b) => GEq (a :*: b :: k -> Type) | Since: some-1.0.4 |
| (GEq f, GEq g) => GEq (f :+: g :: k -> Type) | Since: some-1.0.4 |
class GEq f => GCompare (f :: k -> Type) 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 SNat | |
| GCompare SChar | |
| GCompare SSymbol | |
| GCompare TagList Source # | |
| GCompare TagMaybe Source # | |
| GCompare TagV Source # | |
| Ord c => GCompare (TagK c :: Type -> Type) Source # | |
| GCompare (TypeRep :: k -> Type) | |
| (GCompare t, GCompare u) => GCompare (TagComp t u :: Type -> Type) Source # | |
| (GCompare t, GCompare u) => GCompare (TagDay t u :: Type -> Type) Source # | |
| (GCompare t1, GCompare t2) => GCompare (TagMul t1 t2 :: Type -> Type) Source # | |
| GCompare t => GCompare (TagPow n t :: Type -> Type) Source # | |
| GCompare t => GCompare (TagPow' n t :: Type -> Type) Source # | |
| GCompare ((:~:) a :: k -> Type) | |
| (GCompare a, GCompare b) => GCompare (Product a b :: k -> Type) | |
| (GCompare a, GCompare b) => GCompare (Sum a b :: k -> Type) | |
| GCompare ((:~~:) a :: k -> Type) | Since: some-1.0.4 |
| (GCompare a, GCompare b) => GCompare (a :*: b :: k -> Type) | Since: some-1.0.4 |
| (GCompare f, GCompare g) => GCompare (f :+: g :: k -> Type) | Since: some-1.0.4 |
data GOrdering (a :: k) (b :: 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 :: forall {k} (a :: k) (b :: k). GOrdering a b | |
| GEQ :: forall {k} (a :: k). GOrdering a a | |
| GGT :: forall {k} (a :: k) (b :: k). GOrdering a b |
Instances
| GRead (GOrdering a :: k -> Type) | |
Defined in Data.GADT.Internal Methods greadsPrec :: Int -> GReadS (GOrdering a) # | |
| GShow (GOrdering a :: k -> Type) | |
Defined in Data.GADT.Internal Methods gshowsPrec :: forall (a0 :: k). Int -> GOrdering a a0 -> ShowS # | |
| Show (GOrdering a b) | |
| Eq (GOrdering a b) | |
| Ord (GOrdering a b) | |
Defined in Data.GADT.Internal Methods compare :: GOrdering a b -> GOrdering a b -> Ordering # (<) :: GOrdering a b -> GOrdering a b -> Bool # (<=) :: GOrdering a b -> GOrdering a b -> Bool # (>) :: GOrdering a b -> GOrdering a b -> Bool # (>=) :: GOrdering a b -> GOrdering a b -> Bool # | |