0 | module Pipeline.Basic
2 | import public Data.Vect
3 | import public Data.Vect.Utils
4 | import public Data.Vect.Quantifiers
8 | Pipeline : Nat -> Type
9 | Pipeline length = Vect length Type
12 | Fn : Type -> Type -> Type
16 | KleisliFn : (Type -> Type) -> Type -> Type -> Type
17 | KleisliFn m x y = x -> m y
20 | Impl : Pipeline (2 + n) -> Type
21 | Impl cs = All (uncurry Fn) (pairUp cs)
24 | Run : (p : Pipeline (2 + n)) -> Impl p -> head p -> last p
25 | Run [x, y] [f] v = f v
26 | Run (s :: t :: x :: xs) (f :: cont) v = Run (t :: x :: xs) cont (f v)
29 | RunTrace : (p : Pipeline (2 + n)) -> (print : All Show p) => Impl p -> head p -> last p
30 | RunTrace {print = [p, q]} [x, y] [f] v = traceValBy show (f v)
31 | RunTrace {print = p :: q :: ps} (s :: t :: x :: xs) (f :: cont) v =
32 | Run (t :: x :: xs) cont (traceValBy show (f v))
34 | parameters {m : Type -> Type}
37 | ImplM : Pipeline (2 + n) -> Type
38 | ImplM cs = All (uncurry (KleisliFn m)) (pairUp cs)
41 | RunM : (mon : Monad m) => (p : Pipeline (2 + n)) -> ImplM p -> Vect.head p -> m (Vect.last p)
43 | RunM (x :: y :: z :: xs) (f :: c) = RunM (y :: z :: xs) c <=< f
46 | RunTraceM : Monad m => (p : Pipeline (2 + n)) -> (print : All Show p) => ImplM {m} p -> Vect.head p -> m (Vect.last p)
47 | RunTraceM [x, y] {print = [p1, p2]} [f] = f >=> pure . traceValBy show
48 | RunTraceM (x :: y :: z :: xs) {print = p :: q :: ps} (f :: c) =
49 | f >=> pure . traceValBy show >=> RunTraceM (y :: z :: xs) c