Copyright | (c) Eitan Chatav 2019 |
---|---|
Maintainer | eitan@morphism.tech |
Stability | experimental |
Safe Haskell | Safe |
Language | Haskell2010 |
Consider the category of Haskell "quivers" with
- objects are types of higher kind
p :: k -> k -> Type
- morphisms are terms of
RankNType
, forall x y. p x y -> q x y
- identity is
id
- composition is
.
Now, consider the subcategory of Haskell Category
s with
- constrained objects
Category
c => c
- morphisms act functorially
t :: (Category c, Category d) => c x y -> d x y
t id = id
t (g . f) = t g . t f
The free category functor
from quivers to Category
s may be defined up to isomorphism as
Synopsis
- data Path p x y where
- pattern (:<<) :: Path p y z -> p x y -> Path p x z
- newtype FoldPath p x y = FoldPath {
- getFoldPath :: forall q. Category q => (forall x y. p x y -> q x y) -> q x y
- class Category (cat :: k -> k -> Type) where
- class (forall p. Category (c p)) => CFunctor c where
- cmap :: (forall x y. p x y -> q x y) -> c p x y -> c q x y
- class CFunctor c => CFoldable c where
- cfoldMap :: Category q => (forall x y. p x y -> q x y) -> c p x y -> q x y
- cfold :: Category q => c q x y -> q x y
- cfoldr :: (forall x y z. p x y -> q y z -> q x z) -> q y z -> c p x y -> q x z
- cfoldl :: (forall x y z. q x y -> p y z -> q x z) -> q x y -> c p y z -> q x z
- ctoMonoid :: Monoid m => (forall x y. p x y -> m) -> c p x y -> m
- ctoList :: (forall x y. p x y -> a) -> c p x y -> [a]
- ctraverse_ :: (Applicative m, Category q) => (forall x y. p x y -> m (q x y)) -> c p x y -> m (q x y)
- class CFoldable c => CTraversable c where
- ctraverse :: Applicative m => (forall x y. p x y -> m (q x y)) -> c p x y -> m (c q x y)
- class CTraversable c => CFree c where
- csingleton :: p x y -> c p x y
- toPath :: (CFoldable c, CFree path) => c p x y -> path p x y
- newtype EndoL p x y = EndoL {
- getEndoL :: forall w. p w x -> p w y
- newtype EndoR p y x = EndoR {
- getEndoR :: forall z. p x z -> p y z
- newtype MCat m x y = MCat {
- getMCat :: m
- newtype ApCat m c x y = ApCat {
- getApCat :: m (c x y)
Documentation
data Path p x y where Source #
A Path
with steps in p
is a singly linked list of
"type-aligned" constructions of p
.
>>>
:{
let path :: Path (->) String Int path = length :>> (\x -> x^2) :>> Done in cfold path "hello" :} 25
Instances
CFunctor (Path :: (k -> k -> Type) -> k -> k -> Type) Source # | |
CFree (Path :: (k -> k -> Type) -> k -> k -> Type) Source # | |
Defined in Control.Category.Free csingleton :: p x y -> Path p x y Source # | |
CTraversable (Path :: (k -> k -> Type) -> k -> k -> Type) Source # | |
Defined in Control.Category.Free | |
CFoldable (Path :: (k -> k -> Type) -> k -> k -> Type) Source # | |
Defined in Control.Category.Free cfoldMap :: Category q => (forall (x :: k0) (y :: k0). p x y -> q x y) -> Path p x y -> q x y Source # cfold :: Category q => Path q x y -> q x y Source # cfoldr :: (forall (x :: k0) (y :: k0) (z :: k1). p x y -> q y z -> q x z) -> q y z -> Path p x y -> q x z Source # cfoldl :: (forall (x :: k0) (y :: k1) (z :: k1). q x y -> p y z -> q x z) -> q x y -> Path p y z -> q x z Source # ctoMonoid :: Monoid m => (forall (x :: k0) (y :: k0). p x y -> m) -> Path p x y -> m Source # ctoList :: (forall (x :: k0) (y :: k0). p x y -> a) -> Path p x y -> [a] Source # ctraverse_ :: (Applicative m, Category q) => (forall (x :: k0) (y :: k0). p x y -> m (q x y)) -> Path p x y -> m (q x y) Source # | |
Category (Path p :: k -> k -> Type) Source # | |
(forall (x1 :: k) (y1 :: k). Show (p x1 y1)) => Show (Path p x y) Source # | |
x ~ y => Semigroup (Path p x y) Source # | |
x ~ y => Monoid (Path p x y) Source # | |
pattern (:<<) :: Path p y z -> p x y -> Path p x z infixl 7 Source #
The snoc pattern for right-to-left composition.
newtype FoldPath p x y Source #
Encodes a path as its cfoldMap
function.
FoldPath | |
|
Instances
CFunctor (FoldPath :: (k -> k -> Type) -> k -> k -> Type) Source # | |
CFree (FoldPath :: (k -> k -> Type) -> k -> k -> Type) Source # | |
Defined in Control.Category.Free csingleton :: p x y -> FoldPath p x y Source # | |
CTraversable (FoldPath :: (k -> k -> Type) -> k -> k -> Type) Source # | |
Defined in Control.Category.Free | |
CFoldable (FoldPath :: (k -> k -> Type) -> k -> k -> Type) Source # | |
Defined in Control.Category.Free cfoldMap :: Category q => (forall (x :: k0) (y :: k0). p x y -> q x y) -> FoldPath p x y -> q x y Source # cfold :: Category q => FoldPath q x y -> q x y Source # cfoldr :: (forall (x :: k0) (y :: k0) (z :: k1). p x y -> q y z -> q x z) -> q y z -> FoldPath p x y -> q x z Source # cfoldl :: (forall (x :: k0) (y :: k1) (z :: k1). q x y -> p y z -> q x z) -> q x y -> FoldPath p y z -> q x z Source # ctoMonoid :: Monoid m => (forall (x :: k0) (y :: k0). p x y -> m) -> FoldPath p x y -> m Source # ctoList :: (forall (x :: k0) (y :: k0). p x y -> a) -> FoldPath p x y -> [a] Source # ctraverse_ :: (Applicative m, Category q) => (forall (x :: k0) (y :: k0). p x y -> m (q x y)) -> FoldPath p x y -> m (q x y) Source # | |
Category (FoldPath p :: k -> k -> Type) Source # | |
x ~ y => Semigroup (FoldPath p x y) Source # | |
x ~ y => Monoid (FoldPath p x y) Source # | |
class Category (cat :: k -> k -> Type) where #
A class for categories. Instances should satisfy the laws
f.
id
= f -- (right identity)id
.
f = f -- (left identity) f.
(g.
h) = (f.
g).
h -- (associativity)
Instances
Category (Coercion :: k -> k -> Type) | Since: base-4.7.0.0 |
Category ((:~:) :: k -> k -> Type) | Since: base-4.7.0.0 |
Category (Path p :: k -> k -> Type) Source # | |
Category (FoldPath p :: k -> k -> Type) Source # | |
Category ((:~~:) :: k -> k -> Type) | Since: base-4.10.0.0 |
Category (EndoR p :: k1 -> k1 -> Type) Source # | |
Category (EndoL p :: k2 -> k2 -> Type) Source # | |
Monoid m => Category (MCat m :: k -> k -> Type) Source # | |
(Applicative m, Category c) => Category (ApCat m c :: k -> k -> Type) Source # | |
Category ((->) :: Type -> Type -> Type) | Since: base-3.0 |
Defined in Control.Category |
class (forall p. Category (c p)) => CFunctor c where Source #
class CFunctor c => CFoldable c where Source #
cfoldMap :: Category q => (forall x y. p x y -> q x y) -> c p x y -> q x y Source #
Map each element of the structure to a Category
,
and combine the results.
cfold :: Category q => c q x y -> q x y Source #
Combine the elements of a structure using a Category
.
cfoldr :: (forall x y z. p x y -> q y z -> q x z) -> q y z -> c p x y -> q x z Source #
Right-associative fold of a structure.
In the case of Path
s, cfoldr
, when applied to a binary operator,
a starting value, and a Path
, reduces the Path
using the binary operator,
from right to left:
cfoldr (?) q (p1 :>> p2 :>> ... :>> pn :>> Done) == p1 ? (p2 ? ... (pn ? q) ...)
cfoldl :: (forall x y z. q x y -> p y z -> q x z) -> q x y -> c p y z -> q x z Source #
Left-associative fold of a structure.
In the case of Path
s, cfoldl
, when applied to a binary operator,
a starting value, and a Path
, reduces the Path
using the binary operator,
from left to right:
cfoldl (?) q (p1 :>> p2 :>> ... :>> pn :>> Done) == (... ((q ? p1) ? p2) ? ...) ? pn
ctoMonoid :: Monoid m => (forall x y. p x y -> m) -> c p x y -> m Source #
Map each element of the structure to a Monoid
,
and combine the results.
ctoList :: (forall x y. p x y -> a) -> c p x y -> [a] Source #
Map each element of the structure, and combine the results in a list.
ctraverse_ :: (Applicative m, Category q) => (forall x y. p x y -> m (q x y)) -> c p x y -> m (q x y) Source #
Map each element of a structure to an Applicative
on a Category
,
evaluate from left to right, and combine the results.
Instances
CFoldable (FoldPath :: (k -> k -> Type) -> k -> k -> Type) Source # | |
Defined in Control.Category.Free cfoldMap :: Category q => (forall (x :: k0) (y :: k0). p x y -> q x y) -> FoldPath p x y -> q x y Source # cfold :: Category q => FoldPath q x y -> q x y Source # cfoldr :: (forall (x :: k0) (y :: k0) (z :: k1). p x y -> q y z -> q x z) -> q y z -> FoldPath p x y -> q x z Source # cfoldl :: (forall (x :: k0) (y :: k1) (z :: k1). q x y -> p y z -> q x z) -> q x y -> FoldPath p y z -> q x z Source # ctoMonoid :: Monoid m => (forall (x :: k0) (y :: k0). p x y -> m) -> FoldPath p x y -> m Source # ctoList :: (forall (x :: k0) (y :: k0). p x y -> a) -> FoldPath p x y -> [a] Source # ctraverse_ :: (Applicative m, Category q) => (forall (x :: k0) (y :: k0). p x y -> m (q x y)) -> FoldPath p x y -> m (q x y) Source # | |
CFoldable (Path :: (k -> k -> Type) -> k -> k -> Type) Source # | |
Defined in Control.Category.Free cfoldMap :: Category q => (forall (x :: k0) (y :: k0). p x y -> q x y) -> Path p x y -> q x y Source # cfold :: Category q => Path q x y -> q x y Source # cfoldr :: (forall (x :: k0) (y :: k0) (z :: k1). p x y -> q y z -> q x z) -> q y z -> Path p x y -> q x z Source # cfoldl :: (forall (x :: k0) (y :: k1) (z :: k1). q x y -> p y z -> q x z) -> q x y -> Path p y z -> q x z Source # ctoMonoid :: Monoid m => (forall (x :: k0) (y :: k0). p x y -> m) -> Path p x y -> m Source # ctoList :: (forall (x :: k0) (y :: k0). p x y -> a) -> Path p x y -> [a] Source # ctraverse_ :: (Applicative m, Category q) => (forall (x :: k0) (y :: k0). p x y -> m (q x y)) -> Path p x y -> m (q x y) Source # |
class CFoldable c => CTraversable c where Source #
Generalizing Traversable
to Category
s.
ctraverse :: Applicative m => (forall x y. p x y -> m (q x y)) -> c p x y -> m (c q x y) Source #
Map each element of a structure to an Applicative
on a quiver,
evaluate from left to right, and collect the results.
Instances
CTraversable (Path :: (k -> k -> Type) -> k -> k -> Type) Source # | |
Defined in Control.Category.Free | |
CTraversable (FoldPath :: (k -> k -> Type) -> k -> k -> Type) Source # | |
Defined in Control.Category.Free |
class CTraversable c => CFree c where Source #
Unpacking the definition of a left adjoint to the forgetful functor
from Category
s to quivers, there must be a function csingleton
,
such that any function
f :: Category d => p x y -> d x y
factors uniquely through c p x y
as
cfoldMap f . csingleton = f
csingleton :: p x y -> c p x y Source #
Used in the default definition of cfoldr
.
Used in the default definition of cfoldr
.
Instances
Monoid m => Category (MCat m :: k -> k -> Type) Source # | |
Eq m => Eq (MCat m x y) Source # | |
Ord m => Ord (MCat m x y) Source # | |
Show m => Show (MCat m x y) Source # | |
newtype ApCat m c x y Source #
Turn an Applicative
over a Category
into a Category
,
used in the default definition of ctraverse_
.
Instances
(Applicative m, Category c) => Category (ApCat m c :: k -> k -> Type) Source # | |
Eq (m (c x y)) => Eq (ApCat m c x y) Source # | |
Ord (m (c x y)) => Ord (ApCat m c x y) Source # | |
Defined in Control.Category.Free compare :: ApCat m c x y -> ApCat m c x y -> Ordering # (<) :: ApCat m c x y -> ApCat m c x y -> Bool # (<=) :: ApCat m c x y -> ApCat m c x y -> Bool # (>) :: ApCat m c x y -> ApCat m c x y -> Bool # (>=) :: ApCat m c x y -> ApCat m c x y -> Bool # | |
Show (m (c x y)) => Show (ApCat m c x y) Source # | |