Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
158 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
{-# LANGUAGE PolyKinds #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
|
||
module Math.Groupoid where | ||
|
||
import Math.Category | ||
|
||
class Category p => Groupoid p where | ||
inv :: p a b -> p b a | ||
|
||
instance (Groupoid p, Op p ~ Yoneda p) => Groupoid (Yoneda p) where | ||
inv (Op f) = Op (inv f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,63 @@ | ||
{-# LANGUAGE ConstraintKinds #-} | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE KindSignatures #-} | ||
{-# LANGUAGE PolyKinds #-} | ||
{-# LANGUAGE RankNTypes #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
{-# LANGUAGE TypeOperators #-} | ||
{-# LANGUAGE GADTs #-} | ||
module Math.Multicategory where | ||
|
||
module Math.Multicategory | ||
( Forest(..) | ||
, Multicategory(..) | ||
-- * Utilities | ||
, inputs, outputs | ||
, splitForest | ||
) where | ||
|
||
import Data.Constraint | ||
import Data.Proxy | ||
import Math.Category | ||
import Math.Rec | ||
import Math.Rec.All | ||
import Prelude (($), undefined) | ||
|
||
data Forest :: ([i] -> i -> *) -> [i] -> [i] -> * where | ||
Nil :: Forest f '[] '[] | ||
Cons :: f k o -> Forest f m n -> Forest f (k ++ m) (o ': n) | ||
(:-) :: f k o -> Forest f m n -> Forest f (k ++ m) (o ': n) | ||
|
||
inputs :: forall f g is os. (forall as b. f as b -> Rec g as) -> Forest f is os -> Rec g is | ||
inputs _ Nil = RNil | ||
inputs f (Cons a as) = f a `appendRec` inputs f as | ||
inputs f (a :- as) = f a `appendRec` inputs f as | ||
|
||
outputs :: (forall as b. f as b -> p b) -> Forest f is os -> Rec p os | ||
outputs f Nil = RNil | ||
outputs f (Cons a as) = f a :& outputs f as | ||
outputs f (a :- as) = f a :& outputs f as | ||
|
||
splitForest :: forall f g ds is js os r. Rec f is -> Forest g js os -> Forest g ds (is ++ js) -> (forall bs cs. (ds ~ (bs ++ cs)) => Forest g bs is -> Forest g cs js -> r) -> r | ||
splitForest RNil bs as k = k Nil as | ||
splitForest (i :& is) bs ((j :: g as o) :- js) k = splitForest is bs js $ \ (l :: Forest g bs as1) (r :: Forest g cs js) -> | ||
case appendAssocAxiom (Proxy :: Proxy as) (Proxy :: Proxy bs) (Proxy :: Proxy cs) of | ||
Dict -> k (j :- l) r | ||
|
||
class Multicategory (f :: [i] -> i -> *) where | ||
type Mob f :: i -> Constraint | ||
type Mob f = Vacuous | ||
ident :: Mob f a => f '[a] a | ||
compose :: f bs c -> Forest f as bs -> f as c | ||
msources :: f as b -> Rec (Dict1 (Mob f)) as | ||
mtarget :: f as b -> Dict (Mob f b) | ||
ident :: Mob f a => f '[a] a | ||
compose :: f bs c -> Forest f as bs -> f as c | ||
sources :: f as b -> Rec (Dict1 (Mob f)) as | ||
mtarget :: f as b -> Dict1 (Mob f) b | ||
|
||
instance Multicategory f => Category (Forest f) where | ||
type Ob (Forest f) = All (Mob f) | ||
id = undefined -- Cons ident Nil | ||
(.) = undefined | ||
source = undefined | ||
target = undefined | ||
id = go proofs where | ||
go :: Rec (Dict1 (Mob f)) is -> Forest f is is | ||
go (Dict1 :& as) = ident :- idents as | ||
go RNil = Nil | ||
|
||
Nil . Nil = Nil | ||
(b :- bs) . as = splitForest (sources b) bs as $ \es fs -> compose b es :- (bs . fs) | ||
|
||
source = reproof . inputs sources | ||
target = reproof . outputs mtarget |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters