0 | module Data.CT.Functor.Instances
2 | import Data.CT.Category.Definition
3 | import Data.CT.Category.Instances
4 | import Data.CT.Functor.Definition
7 | import Data.Container.Base
8 | import Data.Container.Additive
12 | id = MkFunctor id id
16 | IndCat : (c : Cat) -> Type
17 | IndCat c = Functor c (opCat Cat)
20 | Const : {c : Cat} -> IndCat c
21 | Const = MkFunctor (\_ => c) (\_ => id)
25 | FamObj : {c : Cat} -> (a : Type) -> Cat
26 | FamObj a = MkCat (a -> c.Obj) (\a', b' => (x : a) -> c.Hom (a' x) (b' x))
29 | FamMor : {c : Cat} ->
30 | {0 x, y : Type} -> (x -> y) -> Functor (FamObj {c=c} y) (FamObj {c=c} x)
31 | FamMor f = MkFunctor (. f) (\j, xx => j (f xx))
35 | FamIndCat : {c : Cat} -> IndCat TypeCat
36 | FamIndCat = MkFunctor (\a => FamObj {c=c} a) FamMor
40 | Base : Functor DLens TypeCat
41 | Base = MkFunctor Shp (.fwd)
45 | FamDLens : {c : Cat} -> IndCat DLens
46 | FamDLens = composeFunctors Base (FamIndCat {c=c})
50 | AddBase : Functor AddDLens TypeCat
51 | AddBase = MkFunctor (.Shp) (.fwd)
54 | FamAddDLens : {c : Cat} -> IndCat AddDLens
55 | FamAddDLens = composeFunctors AddBase (FamIndCat {c=c})
61 | IndexedType : Type -> Type
62 | IndexedType a = a -> Type
65 | TypeDPair : {a : Type} -> IndexedType a -> Type
66 | TypeDPair fam = (x : a ** fam x)
69 | TypeDFun : {a : Type} -> IndexedType a -> Type
70 | TypeDFun fam = (x : a) -> fam x
75 | IndexedCont : Cont -> Type
76 | IndexedCont c = c.Shp -> Cont
79 | ContDPair : {a : Cont} -> IndexedCont a -> Cont
80 | ContDPair a' = ((
x ** t)
: DPair a.Shp (Shp . a')) !> (a' x).Pos t
83 | ContProbDPair : {a : Cont} -> IndexedCont a -> Cont
84 | ContProbDPair a' = (((x, d) ** t) : DPair (a.Shp, Double) (Shp . a' . fst)) !>
89 | IndexedAddCont : AddCont -> Type
90 | IndexedAddCont c = c.Shp -> AddCont
93 | AddContDPair : {a : AddCont} -> IndexedAddCont a -> AddCont
94 | AddContDPair a' = MkAddCont
95 | (DPair a.Shp (\x => (a' x).Shp))
96 | (\(
x ** x')
=> (a' x).Pos x')
100 | AddContDFunFinite : {n : Nat} -> (Fin n -> AddCont) -> AddCont
101 | AddContDFunFinite {n = 0} i = UnitCont
102 | AddContDFunFinite {n = (S k)} i = i 0 >*< AddContDFunFinite (i . FS)
105 | indexShp : {n : Nat} -> {i : Fin n -> AddCont} ->
107 | (AddContDFunFinite i).Shp -> (i j).Shp
108 | indexShp {n = (S k)} FZ (s, _) = s
109 | indexShp {n = (S k)} {i} (FS y) (_, ss) = indexShp {i=i . FS} y ss
112 | injectPos : {n : Nat} -> {f : Fin n -> AddCont} ->
113 | (j : Fin n) -> (bp : (AddContDFunFinite f).Shp) ->
114 | (f j).PosSet (indexShp {i=f} j bp) ->
115 | (AddContDFunFinite f).PosSet bp
116 | injectPos {n = S k} FZ (p, rest) g =
117 | (g, (AddContDFunFinite (f . FS)).Zero rest)
118 | injectPos {n = S k} {f} (FS j) (p, rest) g =
119 | ((f FZ).Zero p, injectPos {f=f . FS} j rest g)
124 | graph : {n : Nat} -> {br : Vect n AddCont} ->
125 | AddContDFunFinite (\i => index i br) =%+> Vect n >-+@ Coproduct br
127 | (
() <| (\i => (
i ** indexShp {i = \i => index i br} i s)
) **
128 | fromGenerators {y = (AddContDFunFinite (\i => index i br)).Pos s}
129 | (\(
i ** g)
=> injectPos {f = \i => index i br} i s g))
132 | AddContDFunction : {a : AddCont} -> IndexedAddCont a -> AddCont
133 | AddContDFunction a' = MkAddCont
134 | ((x : a.Shp) -> (a' x).Shp)
135 | (\s => (
((x : a.Shp) -> (a' x).PosSet (s x)) ** MkComMonoid
136 | (\l, r => \x => (a' x).Plus (s x) (l x) (r x))
137 | (\x => (a' x).Zero (s x)))
)
148 | ContDPairSimple : (c : Cont) -> IndexedCont c -> Cont
149 | ContDPairSimple c fam =
150 | (st : (s : c.Shp ** (fam s).Shp)) !>
151 | (fam (fst st)).Pos (snd st)
164 | ContDFun : (c : Cont) -> IndexedCont c -> Cont
166 | (f : ((s : c.Shp) -> (fam s).Shp)) !>
167 | (s : c.Shp ** (p : c.Pos s ** (fam s).Pos (f s)))
175 | constFam : {c : Cont} -> Cont -> IndexedCont c
176 | constFam d = \_ => d
180 | trivialFam : {c : Cont} -> IndexedCont c
181 | trivialFam = \_ => ((_ : ()) !> Void)
185 | boolFam : {c : Cont} -> IndexedCont c
186 | boolFam = \_ => ((_ : Bool) !> Void)