0 | module Stellar.API.Definition
2 | import public Stellar.Ops
5 | import Data.Coproduct
14 | response : message -> Type
16 | %pair API message response
21 | Continuation : API -> Type
22 | Continuation a = (x : a.message) -> a.response x
27 | (:-) : Type -> Type -> API
28 | (:-) ty sy = (x : ty) !> sy
32 | Through : Type -> API
33 | Through ty = ty :- ty
43 | Never = Void :- Void
48 | Forever = Unit :- Void
52 | (+) : (c1, c2 : API) -> API
53 | (+) c1 c2 = (!>) (c1.message + c2.message) (choice c1.response c2.response)
57 | (*) : (c1, c2 : API) -> API
58 | (*) c1 c2 = (x : c1.message * c2.message) !> c1.response x.π1 + c2.response x.π2
62 | (//) : (c1, c2 : API) -> API
63 | (//) c1 c2 = (x : c1.message * c2.message) !> c1.response x.π1 * c2.response x.π2
67 | record Ex (c : API) (ty : Type) where
74 | cont : c.response req -> ty
78 | (&>) : (c1, c2 : API) -> API
79 | (&>) c1 c2 = (x : Ex c1 c2.message)
80 | !> Σ (c1.response x.req) (c2.response . x.cont)
84 | (#>) : (c1, c2 : API) -> API
85 | (#>) c1 c2 = (x : Ex c1 c2.message)
86 | !> ((y : c1.response x.req) -> c2.response (x.cont y))
90 | (c : API) => Functor (Ex c) where
91 | map f x = (MkEx x.req (f . x.cont))
95 | Lift : (f : Type -> Type) -> API -> API
96 | Lift f c = (x : c.message) !> f (c.response x)
99 | ($-) : (f : Type -> Type) -> API -> API
104 | Send c = c.message :- Unit