0 | module Pipeline.Category
2 | import Control.Category
3 | import Pipeline.Basic
4 | import Data.Category.Graded
5 | import public Data.Vect
6 | import public Data.Vect.Utils
7 | import public Data.Vect.Quantifiers
10 | parameters {0 obj : Type} {0 arr : obj -> obj -> Type}
14 | ImplCat : Vect (2 + n) obj -> Type
15 | ImplCat xs = All (uncurry arr) (pairUp xs)
20 | RunCat : {auto cat : Category {obj} arr} -> (p : Vect (2 + n) obj) -> ImplCat p -> Vect.head p `arr` Vect.last p
21 | RunCat [x, y] [f] = f
22 | RunCat (x :: y :: z :: xs) (f :: c) = RunCat (y :: z :: xs) c . f
26 | interface CoprodStrength (mon : Monoid a) (f : a -> Type) | f where
27 | constructor MkFCoprod
28 | left : {x, y : _} -> f x -> f (x <+> y)
29 | right : {x, y : _} -> f y -> f (x <+> y)
33 | CoprodStrength EitherMon (\x => x) using EitherSem where
39 | CoprodStrength AnyMon OneOf using AnySem where
47 | [Set] Category Fn where
54 | MkInst : {0 gr : Type} -> {f : gr -> Type} -> (mon : Monoid gr) => (fc : CoprodStrength mon f) => GradedCat mon (GradedCoproductMonad {e = gr} f)
55 | MkInst {fc = MkFCoprod ll rr} = MkGradedCat Right
56 | (\m1, m2 => (mapFst ll . m1) @{Set} >=> (mapFst rr . m2) @{Set})
61 | foldGrades : Monoid gr => Vect (S n) gr -> gr
62 | foldGrades (x :: []) = x
63 | foldGrades (x :: (y :: xs)) = x <+> foldGrades (y :: xs)
67 | parameters {0 gr : Type} {0 obj : Type} {0 arr : gr -> obj -> obj -> Type}
73 | ImplGr : forall n. Vect (2 + n) obj -> Vect (S n) gr -> Type
74 | ImplGr layers grades = All (\arg => arr (fst arg) (fst (snd arg)) (snd (snd arg))) (zip grades (pairUp layers))
81 | RunGrCat : forall n. {auto mon : Monoid gr} -> (cat : GradedCat mon arr) -> (p : Vect (2 + n) obj) -> (grades : Vect (S n) gr) ->
82 | ImplGr p grades -> arr (foldGrades grades) (Vect.head p) (Vect.last p)
83 | RunGrCat cat [x, y] [gr] [f] = f
84 | RunGrCat cat (x :: y :: z :: xs) (gr1 :: (g :: gs)) (f :: c :: cs) =
85 | f #> RunGrCat cat (y :: z :: xs) (g :: gs) (c :: cs)