| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
| Extensions |
|
Control.Category.Free
Synopsis
- data Cat (f :: k -> k -> *) a b where
- arrCat :: forall (f :: k -> k -> *) a b. f a b -> Cat f a b
- mapCat :: forall (f :: k -> k -> *) a b c. f b c -> Cat f a b -> Cat f a c
- foldCat :: forall f c a b. Category c => (forall x y. f x y -> c x y) -> Cat f a b -> c a b
- newtype C f a b = C {}
- toC :: ListTr f a b -> C f a b
- fromC :: C f a b -> ListTr f a b
- newtype Op (f :: k -> k -> *) (a :: k) (b :: k) = Op {
- runOp :: f b a
- class FreeAlgebra2 (m :: (k -> k -> Type) -> k -> k -> Type) where
- liftFree2 :: AlgebraType0 m f => f a b -> m f a b
- foldNatFree2 :: (AlgebraType m d, AlgebraType0 m f) => (forall (x :: k) (y :: k). f x y -> d x y) -> m f a b -> d a b
- codom2 :: AlgebraType0 m f => Proof (AlgebraType m (m f)) (m f)
- forget2 :: AlgebraType m f => Proof (AlgebraType0 m f) (m f)
- wrapFree2 :: (AlgebraType0 m f, FreeAlgebra2 m, Monad (m f a)) => f a (m f a b) -> m f a b
- foldFree2 :: (FreeAlgebra2 m, AlgebraType m f) => m f a b -> f a b
- hoistFree2 :: (FreeAlgebra2 m, AlgebraType0 m g, AlgebraType0 m f) => (forall (x :: k) (y :: k). f x y -> g x y) -> m f a b -> m g a b
- joinFree2 :: (FreeAlgebra2 m, AlgebraType0 m f) => m (m f) a b -> m f a b
- bindFree2 :: (FreeAlgebra2 m, AlgebraType0 m g, AlgebraType0 m f) => m f a b -> (forall (x :: k) (y :: k). f x y -> m g x y) -> m g a b
Free category
data Cat (f :: k -> k -> *) a b where Source #
Efficient encoding of a category for which morphism composition has
O(1) complexity and fold is linear in the number of transitions.
Instances
| FreeAlgebra2 (Cat :: (k -> k -> Type) -> k -> k -> Type) Source # | complexity of |
Defined in Control.Category.Free Methods liftFree2 :: AlgebraType0 Cat f => f a b -> Cat f a b # foldNatFree2 :: (AlgebraType Cat d, AlgebraType0 Cat f) => (forall (x :: k0) (y :: k0). f x y -> d x y) -> Cat f a b -> d a b # codom2 :: AlgebraType0 Cat f => Proof (AlgebraType Cat (Cat f)) (Cat f) # forget2 :: AlgebraType Cat f => Proof (AlgebraType0 Cat f) (Cat f) # | |
| Category (Cat f :: k -> k -> Type) Source # | complexity of composition |
| Arrow f => Arrow (Cat f) Source # | |
| ArrowZero f => ArrowZero (Cat f) Source # | |
Defined in Control.Category.Free | |
| ArrowChoice f => ArrowChoice (Cat f) Source # | |
| Semigroup (Cat f o o) Source # | |
| Monoid (Cat f o o) Source # | |
| type AlgebraType0 (Cat :: (k -> k -> Type) -> k -> k -> Type) (f :: l) Source # | |
Defined in Control.Category.Free | |
| type AlgebraType (Cat :: (k2 -> k2 -> Type) -> k2 -> k2 -> Type) (c :: k1 -> k1 -> Type) Source # | |
Defined in Control.Category.Free | |
foldCat :: forall f c a b. Category c => (forall x y. f x y -> c x y) -> Cat f a b -> c a b Source #
Right fold of Cat into a category, the same as .foldNatFree2 @Cat
complexity: O(n) where n@ is number of transition embedded in Cat.
Free category (CPS style)
CPS style encoded free category; one can use class
instance:FreeAlgebra2
liftFree2 @C :: f a b -> C f a b
foldNatFree2 @C :: Category d => (forall x y. f x y -> d x y) -> C f a b -> d a b
Instances
| FreeAlgebra2 (C :: (k -> k -> Type) -> k -> k -> Type) Source # | |
Defined in Control.Category.Free Methods liftFree2 :: AlgebraType0 C f => f a b -> C f a b # foldNatFree2 :: (AlgebraType C d, AlgebraType0 C f) => (forall (x :: k0) (y :: k0). f x y -> d x y) -> C f a b -> d a b # codom2 :: AlgebraType0 C f => Proof (AlgebraType C (C f)) (C f) # forget2 :: AlgebraType C f => Proof (AlgebraType0 C f) (C f) # | |
| Category (C f :: k -> k -> Type) Source # | |
| Arrow f => Arrow (C f) Source # | |
| ArrowZero f => ArrowZero (C f) Source # | |
Defined in Control.Category.Free | |
| ArrowChoice f => ArrowChoice (C f) Source # | |
| Semigroup (C f o o) Source # | |
| Monoid (C f o o) Source # | |
| type AlgebraType0 (C :: (k -> k -> Type) -> k -> k -> Type) (f :: l) Source # | |
Defined in Control.Category.Free | |
| type AlgebraType (C :: (k2 -> k2 -> Type) -> k2 -> k2 -> Type) (c :: k1 -> k1 -> Type) Source # | |
Defined in Control.Category.Free | |
toC :: ListTr f a b -> C f a b Source #
Isomorphism from to Cat, which is a specialisation of
C.hoistFreeH2
fromC :: C f a b -> ListTr f a b Source #
Inverse of , which also is a specialisatin of fromC.hoistFreeH2
Oposite category
newtype Op (f :: k -> k -> *) (a :: k) (b :: k) Source #
Oposite categoy in which arrows from a to b are represented by arrows
from b to a in the original category.
Free interface re-exports
class FreeAlgebra2 (m :: (k -> k -> Type) -> k -> k -> Type) where #
Free algebra class similar to and FreeAlgebra1, but for
types of kind FreeAlgebrak -> k -> Type.
Methods
liftFree2 :: AlgebraType0 m f => f a b -> m f a b #
Lift a graph f satsifying the constraint to
a free its object AlgebraType0m f.
foldNatFree2 :: (AlgebraType m d, AlgebraType0 m f) => (forall (x :: k) (y :: k). f x y -> d x y) -> m f a b -> d a b #
This represents the theorem that m f is indeed free object (as
in propositions as types). The types of kind k -> k -> Type form
a category, where an arrow from f :: k -> k -> Type to d :: k ->
k -> Type is represented by type forall x y. f x y -> d x y.
foldNatFree2 states that whenever we have such a morphism and d
satisfies the constraint AlgebraType m d then we can construct
a morphism from m f to d.
codom2 :: AlgebraType0 m f => Proof (AlgebraType m (m f)) (m f) #
A proof that for each f satisfying AlgebraType0 m f, m f
satisfies AlgebraType m (m f) constrant. This means that m is
a well defined functor from the full sub-category of types of
kind k -> k -> Type which satisfy the AlgebraType0 m constraint
to the full subcategory of types of the same kind which satifsfy
the constraint AlgebraType m.
forget2 :: AlgebraType m f => Proof (AlgebraType0 m f) (m f) #
A proof that each type f :: k -> k -> Type satisfying the
Algebra m f constraint also satisfies AlgebraType0 m f. This
states that there is a well defined forgetful functor from the
category of types of kind k -> k -> Type which satisfy the
AlgebraType m to the category of types of the same kind which
satisfy the AlgebraType0 m constraint.
Instances
wrapFree2 :: (AlgebraType0 m f, FreeAlgebra2 m, Monad (m f a)) => f a (m f a b) -> m f a b #
A version of wrap from free package but for graphs.
foldFree2 :: (FreeAlgebra2 m, AlgebraType m f) => m f a b -> f a b #
hoistFree2 :: (FreeAlgebra2 m, AlgebraType0 m g, AlgebraType0 m f) => (forall (x :: k) (y :: k). f x y -> g x y) -> m f a b -> m g a b #
Hoist the underlying graph in the free structure.
This is a higher version of a functor (analogous to , which
defined functor instance for fmapFree instances) and it satisfies the
functor laws:FreeAlgebra
hoistFree2 id = id
hoistFree2 f . hoistFree2 g = hoistFree2 (f . g)
joinFree2 :: (FreeAlgebra2 m, AlgebraType0 m f) => m (m f) a b -> m f a b #
is a monad on some subcategory of graphs (types of kind
FreeAlgebra2 mk -> k -> Type), it is the joinFreejoin of this monad.
bindFree2 :: (FreeAlgebra2 m, AlgebraType0 m g, AlgebraType0 m f) => m f a b -> (forall (x :: k) (y :: k). f x y -> m g x y) -> m g a b #
bind of the monad defined by m on the subcategory of graphs (typed of
kind k -> k -> Type).