0 | module Pipeline.Basic
2 | import public Data.Vect
3 | import public Data.Vect.Erased
4 | import public Data.Vect.Quantifiers
9 | Pipeline : Nat -> Type
10 | Pipeline length = Vect0 length Type
13 | Impl : Pipeline (2 + n) -> Type
14 | Impl cs = All0 (uncurry Fn) (pairUp cs)
17 | Run : (p : Pipeline (2 + n)) -> Impl p -> Head p -> Last p
18 | Run [x, y] [f] v = f v
19 | Run (s :: t :: x :: xs) (f :: cont) v = Run (t :: x :: xs) cont (f v)
22 | RunTrace : (p : Pipeline (2 + n)) -> (print : All0 Show p) => Impl p -> Head p -> Last p
23 | RunTrace {print = [p, q]} [x, y] [f] v = traceValBy show (f v)
24 | RunTrace {print = p :: q :: ps} (s :: t :: x :: xs) (f :: cont) v =
25 | Run (t :: x :: xs) cont (traceValBy show (f v))
27 | parameters (m : Type -> Type)
30 | ImplM : Pipeline (2 + n) -> Type
31 | ImplM cs = All0 (uncurry (KleisliFn m)) (pairUp cs)
34 | RunM : (mon : Monad m) => (p : Pipeline (2 + n)) -> ImplM p -> Head p -> m (Last p)
36 | RunM (x :: y :: z :: xs) (f :: c) = RunM (y :: z :: xs) c <=< f
39 | RunTraceM : Monad m => (p : Pipeline (2 + n)) -> (print : All0 Show p) => ImplM p -> Head p -> m (Last p)
40 | RunTraceM [x, y] {print = [p1, p2]} [f] = f >=> pure . traceValBy show
41 | RunTraceM (x :: y :: z :: xs) {print = p :: q :: ps} (f :: c) =
42 | f >=> pure . traceValBy show >=> RunTraceM (y :: z :: xs) c
44 | data Cmd : Type where
46 | data Content : Type where
48 | data Output : Type where
50 | example : Vect0 ?
Type
56 | , Maybe (IO Content)
60 | distIOMaybe : Maybe (IO a) -> IO (Maybe a)
61 | distIOMaybe Nothing = pure Nothing
62 | distIOMaybe (Just x) = map pure x
64 | runExample : String -> Maybe (IO Output)
65 | runExample = Run example
69 | , map (>>= ?readContent
)
70 | , map (>>= ?printOutput
)