| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Circuit.Body
Description
A span-shaped Mealy machine: a morphism across a tensored channel.
Body t ch arr a b = arr (t ch a) (t ch b)
Both the channel and the payload enter together, and both exit together.
System specializes this shape to a Moore machine over a
polynomial interface; Process is the pointed monomial
special case of that.
Anatomy
t— tensor: the bifunctor that pairs a channel with a payload. Common choices are(,)for simultaneous sharing,Eitherfor sequential iteration, andThesefor scheduled interleaving.
ch— channel: the value threaded alongside the payload. It may be state, residual, a stream, or a feedback wire.arr— arrow / morphism: the base category. Usually(->)or a Kleisli arrowK m.
This arrangement is the common shape underlying loops, processes, systems,
and channel ends: a morphism whose input and output both carry an ambient
channel. Body makes that shape explicit before any tracing, scheduling,
or pole-splitting is added.
Synopsis
- newtype Body (t :: k -> k1 -> k2) (ch :: k) (arr :: k2 -> k2 -> Type) (a :: k1) (b :: k1) = Body {
- morphism :: arr (t ch a) (t ch b)
- data SomeBody (t :: Type -> k -> k1) (arr :: k1 -> k1 -> Type) (a :: k) (b :: k) where
- runSomeBody :: SomeBody (,) (->) a b -> [a] -> [b]
- runFlowchart :: Body Either ch (->) a b -> Int -> a -> (Maybe b, Int)
- cascadeBody :: forall {k} (t :: k -> k -> k) (arr :: k -> k -> Type) (ch' :: k) (b :: k) (c :: k) (ch :: k) (a :: k). Strength t arr => Body t ch' arr b c -> Body t ch arr a b -> Body t (t ch ch') arr a c
- cascadeSome :: SomeBody (,) (->) b c -> SomeBody (,) (->) a b -> SomeBody (,) (->) a c
Knot-body category
newtype Body (t :: k -> k1 -> k2) (ch :: k) (arr :: k2 -> k2 -> Type) (a :: k1) (b :: k1) Source #
A morphism across a tensored channel.
Body t ch arr a b is a morphism arr (t ch a) (t ch b). The channel
ch is threaded alongside the payload by the tensor t; it may be state,
residual, a stream, or any other value the base arrow arr carries along
with the input and output. Composition threads the same channel through
both morphisms.
Instances
| (Monad m, Pointed s) => HasDual Void (Body Either s (K m) :: Type -> Type -> Type) Source # | Unit poles for |
| Pointed s => HasDual Void (Body Either s (->) :: Type -> Type -> Type) Source # | Unit poles for The coproduct case needs a distinguished element of the carrier |
| Monad m => HasDual () (Body (,) s (K m) :: Type -> Type -> Type) Source # | Unit poles for Same shape as the |
| HasDual () (Body (,) s (->) :: Type -> Type -> Type) Source # | Unit poles for The companion discards its input and returns |
| Category arr => Category (Body t ch arr :: k3 -> k3 -> Type) Source # | |
data SomeBody (t :: Type -> k -> k1) (arr :: k1 -> k1 -> Type) (a :: k) (b :: k) where Source #
A Body with its channel type hidden.
Constructors
| SomeBody :: forall {k} {k1} ch (t :: Type -> k -> k1) (arr :: k1 -> k1 -> Type) (a :: k) (b :: k). ch -> Body t ch arr a b -> SomeBody t arr a b |
Instances
| (Strength t arr, Pointed (Unit t), TensorSeed t) => Category (SomeBody t arr :: Type -> Type -> Type) Source # |
The carrier of the composite is the tensor of the two carriers, and the
stored seed is combined with |
runSomeBody :: SomeBody (,) (->) a b -> [a] -> [b] Source #
Run an existentially-packed cartesian body over a list of inputs.
This is the (,) / list specialisation of SomeBody.
runFlowchart :: Body Either ch (->) a b -> Int -> a -> (Maybe b, Int) Source #
Run an Either body as a partial function a -> b with a fuel bound.
Execution starts with the external input a; if the body emits a label
ch the runner feeds Left ch back in, decrementing the fuel.
Returns the result (if any) and the number of steps taken. A flowchart has
no stored state — the input is the entire initial configuration — so there
is no seed parameter. This is the coproduct analogue of runSomeBody:
where (,) bodies run as stream functions, Either bodies run as halting
computations.
Carrier-tensoring composition
cascadeBody :: forall {k} (t :: k -> k -> k) (arr :: k -> k -> Type) (ch' :: k) (b :: k) (c :: k) (ch :: k) (a :: k). Strength t arr => Body t ch' arr b c -> Body t ch arr a b -> Body t (t ch ch') arr a c Source #
cascadeSome :: SomeBody (,) (->) b c -> SomeBody (,) (->) a b -> SomeBody (,) (->) a c Source #
Pointed carrier-tensoring composition for t = (,) and arr = (->).
Seeds pair under the tensor, and the composite can be run with
runSomeBody. This is the pointed counterpart to the unpointed
cascadeBody.