0 | module Pipeline.Category.Graded
2 | import public Data.Category.Graded
3 | import public Control.Set
4 | import public Control.Category
5 | import public Data.Vect
6 | import public Data.Vect.Erased
10 | interface CoprodStrength (mon : Monoid a) (f : a -> Type) | f where
11 | constructor MkFCoprod
12 | left : {x, y : _} -> f x -> f (x <+> y)
13 | right : {x, y : _} -> f y -> f (x <+> y)
17 | CoprodStrength EitherMon (\x => x) using EitherSem where
23 | CoprodStrength AnyMon OneOf using AnySem where
33 | MkInst : {0 gr : Type} -> {f : gr -> Type} -> (mon : Monoid gr) => (fc : CoprodStrength mon f) => GradedCat mon (GradedCoproductMonad {e = gr} f)
34 | MkInst {fc = MkFCoprod ll rr} = MkGradedCat Right
35 | (\m1, m2 => (mapFst ll . m1) @{Set} >=> (mapFst rr . m2) @{Set})
40 | foldGrades : Monoid gr => Vect (S n) gr -> gr
41 | foldGrades (x :: []) = x
42 | foldGrades (x :: (y :: xs)) = x <+> foldGrades (y :: xs)
45 | zip0 : Vect n a -> Vect0 n b -> Vect0 n (a, b)
47 | zip0 (x :: z) (y :: w) = (x, y) :: zip0 z w
51 | parameters {0 gr : Type} {0 obj : Type} {0 arr : gr -> obj -> obj -> Type}
57 | ImplGr : forall n. Vect0 (2 + n) obj -> Vect (S n) gr -> Type
58 | ImplGr layers grades = All0 (\arg => arr (fst arg) (fst (snd arg)) (snd (snd arg))) (zip0 grades (pairUp layers))
65 | RunGrCat : forall n. {auto mon : Monoid gr} -> (cat : GradedCat mon arr) ->
66 | (p : Vect0 (2 + n) obj) ->
67 | (grades : Vect (S n) gr) ->
68 | ImplGr p grades -> arr (foldGrades grades) (Head p) (Last p)
69 | RunGrCat cat [x, y] [gr] [f] = f
70 | RunGrCat cat (x :: y :: z :: xs) (gr1 :: g :: gs) (f :: c :: cs) =
71 | let rest = RunGrCat cat (y :: z :: xs) (g :: gs) (c :: cs)
72 | in (#>) @{cat} {g1 = gr1, x, y, g2 = foldGrades (g :: gs), z = Last (z :: xs)} f rest