| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Circuit
Contents
- Trace (free traced category syntax)
- Polynomial channels
- Body (knot-body category)
- Circ (loose bicategory of bodies with varying carriers)
- Feedback on Circ
- Polynomial interfaces
- Stream transformer (first-input-seeded processes)
- Channel poles (bi-polar effectful/process API; still the right tool for
- Copycat / multiplicative excluded middle
- Boxes
- Free
- Layer tower
- Operators
- Bimonoid (structural rules)
- Dagger (free dagger category)
- SMC
- Net
- Pullback (linear cotangent maps)
- Hyper
- Tensor
- Stamped values
- Additive poles
- Par (multiplicative disjunction)
- Linear implication (internal hom)
- Exponentials
- Channel product
- Shared-medium fusion (the ⅋ connective)
Description
Usage
import Circuit
Lazy feedback (knot-tying)
Use the (,) tensor to tie a lazy knot. The feedback value and output
are produced simultaneously.
>>>let powers (ns, ()) = (1 : map (*2) ns, take 5 ns)>>>trace powers () :: [Integer][1,2,4,8,16]
Iteration
Use the Either tensor for loops that terminate.
>>>let step n = if n < 5 then Left (n + 1) else Right n>>>trace (either step step) (0 :: Int)5
Switching between representations
Trace is the inspectable free-syntax form. Hyper is the final,
coinductive encoding. Convert a Trace to a Hyper with encode, and
observe it with observe (or eliminate it with runHyper).
>>>observe (encode (base (+1) :: Trace (,) (->) Int Int)) 4142
Overview
This library provides three views on feedback:
Trace(in Circuit.Trace) — the initial, inspectable free-syntax.Hyper(in Circuit.Hyper) — the final, coinductive encoding.Body(in Circuit.Body) — the knot-body categoryarr (t ch a) (t ch b), the stateful substrate thatTracehides before tracing. The cartesian instance is `Body (,) ch (->)`.
The Traced class (in Circuit.Channel) abstracts the choice of tensor,
supporting lazy knots with (,), iteration with Either, and scheduling
with These.
All braided, cartesian, and cocartesian structure, plus the fused
parallel composition superpose, lives in Circuit.Tensor.
Core Concepts
- Tensor (
t): The bifunctor pairing a feedback value with a payload inside aTrace(currently @(,),Either, orThesefor scheduling).
- Feedback value: The component that travels around the loop (the first
parameter of the tensor inside a
Trace). - Payload: The value being transformed and emitted (the second
parameter of the tensor inside a
Trace). - Feedback channel: The path the feedback value takes when routed back into the next step.
Verb glossary
Synopsis
- type Trace (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) = Syntax ((SigCompose :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: (SigYank t :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type)) arr
- base :: forall arr a b (t :: Type -> Type -> Type). arr a b -> Trace t arr a b
- yank :: forall t (arr :: Type -> Type -> Type) s a b. Trace t arr (t s a) (t s b) -> Trace t arr a b
- class Strength t arr => Traced (t :: k -> k -> k) (arr :: k -> k -> Type)
- class Channel t arr => Strength (t :: k -> k -> k) (arr :: k -> k -> Type)
- trace :: forall (a :: k) (b :: k) (c :: k). Traced t arr => arr (t a b) (t a c) -> arr b c
- strength :: forall (b :: k) (c :: k) (a :: k). Strength t arr => arr b c -> arr (t a b) (t a c)
- data Channel (arr :: Type -> Type -> Type) (p :: Poly) where
- emitChannel :: forall (p :: Poly). Channel (->) p -> Eval p ()
- commitChannel :: forall (p :: Poly). Channel (->) p -> Dir p -> Channel (->) p
- idChannel :: a -> Channel (->) (Mono a a)
- constChannel :: b -> Channel (->) (Mono a b)
- mapChannel :: forall (p :: Poly) (q :: Poly). (SystemEval p, SystemEval q) => Morphism p q -> Channel (->) p -> Channel (->) q
- 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
- 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
- runSomeBody :: SomeBody (,) (->) a b -> [a] -> [b]
- data Circ (t :: k -> k1 -> k2) (arr :: k2 -> k2 -> Type) (a :: k1) (b :: k1) where
- idCirc :: forall {k2} (t :: k2 -> k2 -> k2) (arr :: k2 -> k2 -> Type) (a :: k2). Strength t arr => Circ t arr a a
- data Sq (t :: k2 -> k1 -> k2) (arr :: k2 -> k2 -> Type) (ch :: k2) (ch' :: k2) (a :: k1) (b :: k1) = Sq {
- carrierMap :: arr ch ch'
- sqSrc :: Body t ch arr a b
- sqTgt :: Body t ch' arr a b
- idSq :: forall {k2} {k1} (arr :: k2 -> k2 -> Type) (t :: k2 -> k1 -> k2) (ch :: k2) (a :: k1) (b :: k1). Category arr => Body t ch arr a b -> Sq t arr ch ch a b
- vcomp :: forall {k2} {k1} (arr :: k2 -> k2 -> Type) (t :: k2 -> k1 -> k2) (ch' :: k2) (ch'' :: k2) (a :: k1) (b :: k1) (ch :: k2). Category arr => Sq t arr ch' ch'' a b -> Sq t arr ch ch' a b -> Sq t arr ch ch'' a b
- data Intertwiner (t :: k2 -> k1 -> k2) (arr :: k2 -> k2 -> Type) (a :: k1) (b :: k1) where
- Intertwiner :: forall {k2} {k1} (t :: k2 -> k1 -> k2) (arr :: k2 -> k2 -> Type) (ch :: k2) (ch' :: k2) (a :: k1) (b :: k1). Sq t arr ch ch' a b -> Intertwiner t arr a b
- withIntertwiner :: forall {k2} {k1} (t :: k2 -> k1 -> k2) (arr :: k2 -> k2 -> Type) (a :: k1) (b :: k1) r. Intertwiner t arr a b -> (forall (ch :: k2) (ch' :: k2). Sq t arr ch ch' a b -> r) -> r
- downThenAcross :: forall {k1} (t :: k1 -> k1 -> k1) arr (ch :: k1) (ch' :: k1) (a :: k1) (b :: k1). Tensor t arr => Sq t arr ch ch' a b -> arr (t ch a) (t ch' b)
- acrossThenDown :: forall {k1} (t :: k1 -> k1 -> k1) arr (ch :: k1) (ch' :: k1) (a :: k1) (b :: k1). Tensor t arr => Sq t arr ch ch' a b -> arr (t ch a) (t ch' b)
- cascade :: forall {k2} (t :: k2 -> k2 -> k2) (arr :: k2 -> k2 -> Type) (b :: k2) (c :: k2) (a :: k2). Strength t arr => Circ t arr b c -> Circ t arr a b -> Circ t arr a c
- unitorLeft :: forall {k1} (t :: k1 -> k1 -> k1) (arr :: k1 -> k1 -> Type) (ch :: k1) (a :: k1) (b :: k1). (Unital t arr, Strength t arr) => Body t ch arr a b -> Intertwiner t arr a b
- unitorRight :: forall {k1} (t :: k1 -> k1 -> k1) (arr :: k1 -> k1 -> Type) (ch :: k1) (a :: k1) (b :: k1). (Unital t arr, Strength t arr) => Body t ch arr a b -> Intertwiner t arr a b
- unitorLeftSq :: forall {k} (t :: k -> k -> k) (arr :: k -> k -> Type) (ch :: k) (a :: k) (b :: k). (Unital t arr, Strength t arr) => Body t ch arr a b -> Sq t arr (t (Unit t) ch) ch a b
- unitorRightSq :: forall {k} (t :: k -> k -> k) (arr :: k -> k -> Type) (ch :: k) (a :: k) (b :: k). (Unital t arr, Strength t arr) => Body t ch arr a b -> Sq t arr (t ch (Unit t)) ch a b
- associator :: forall {k1} (t :: k1 -> k1 -> k1) (arr :: k1 -> k1 -> Type) (ch3 :: k1) (c :: k1) (d :: k1) (ch2 :: k1) (b :: k1) (ch1 :: k1) (a :: k1). Strength t arr => Body t ch3 arr c d -> Body t ch2 arr b c -> Body t ch1 arr a b -> Intertwiner t arr a d
- associatorSq :: forall {k1} (t :: k1 -> k1 -> k1) (arr :: k1 -> k1 -> Type) (ch3 :: k1) (c :: k1) (d :: k1) (ch2 :: k1) (b :: k1) (ch1 :: k1) (a :: k1). Strength t arr => Body t ch3 arr c d -> Body t ch2 arr b c -> Body t ch1 arr a b -> Sq t arr (t (t ch1 ch2) ch3) (t ch1 (t ch2 ch3)) a d
- rightWhisker :: forall {k1} (t :: k1 -> k1 -> k1) (arr :: k1 -> k1 -> Type) (ch :: k1) (ch' :: k1) (a :: k1) (b :: k1) (d :: k1) (c :: k1). (Tensor t arr, Strength t arr) => Sq t arr ch ch' a b -> Body t d arr b c -> Sq t arr (t ch d) (t ch' d) a c
- leftWhisker :: forall {k1} (t :: k1 -> k1 -> k1) (arr :: k1 -> k1 -> Type) (d :: k1) (a' :: k1) (a :: k1) (ch :: k1) (ch' :: k1) (b :: k1). (Tensor t arr, Strength t arr) => Body t d arr a' a -> Sq t arr ch ch' a b -> Sq t arr (t d ch) (t d ch') a' b
- hcompose :: forall {k1} (t :: k1 -> k1 -> k1) (arr :: k1 -> k1 -> Type) (ch2 :: k1) (ch2' :: k1) (b :: k1) (c :: k1) (ch1 :: k1) (ch1' :: k1) (a :: k1). (Tensor t arr, Strength t arr) => Sq t arr ch2 ch2' b c -> Sq t arr ch1 ch1' a b -> Sq t arr (t ch1 ch2) (t ch1' ch2') a c
- whiskerSq :: forall {k1} (t :: k1 -> k1 -> k1) arr (a' :: k1) (a :: k1) (b :: k1) (b' :: k1) (ch :: k1) (ch' :: k1). Tensor t arr => arr a' a -> arr b b' -> Sq t arr ch ch' a b -> Sq t arr ch ch' a' b'
- feedback :: forall {k2} (t :: k2 -> k2 -> k2) (arr :: k2 -> k2 -> Type) (s :: k2) (a :: k2) (b :: k2). Channel t arr => Circ t arr (t s a) (t s b) -> Circ t arr a b
- type System = SystemT (,)
- system :: forall arr s (p :: Poly). arr (s, Dir p) (s, Pos p) -> System arr s p
- runSystem :: forall arr s (p :: Poly). System arr s p -> arr (s, Dir p) (s, Pos p)
- mooreSystem :: (s -> a -> s) -> (s -> b) -> System (->) s (Mono a b)
- type Mono i o = 'Prod ('Const o) ('Exp i)
- data Morphism (p :: Poly) (q :: Poly) where
- Id :: forall (p :: Poly). Morphism p p
- Point :: forall (q :: Poly). Eval q () -> Morphism 'Y q
- ConstMap :: forall a b. (a -> b) -> Morphism ('Const a) ('Const b)
- ExpMap :: forall a b. (a -> b) -> Morphism ('Exp b) ('Exp a)
- Compose :: forall (q1 :: Poly) (q :: Poly) (p :: Poly). Morphism q1 q -> Morphism p q1 -> Morphism p q
- Par :: forall (p1 :: Poly) (p' :: Poly) (q1 :: Poly) (q' :: Poly). Morphism p1 p' -> Morphism q1 q' -> Morphism ('Prod p1 q1) ('Prod p' q')
- Inl :: forall (p :: Poly) (q1 :: Poly). Morphism p ('Sum p q1)
- Inr :: forall (p :: Poly) (p1 :: Poly). Morphism p ('Sum p1 p)
- Case :: forall (p1 :: Poly) (q :: Poly) (q1 :: Poly). Morphism p1 q -> Morphism q1 q -> Morphism ('Sum p1 q1) q
- Fst :: forall (q :: Poly) (q1 :: Poly). Morphism ('Prod q q1) q
- Snd :: forall (p1 :: Poly) (q :: Poly). Morphism ('Prod p1 q) q
- Pair :: forall (p :: Poly) (p1 :: Poly) (q1 :: Poly). Morphism p p1 -> Morphism p q1 -> Morphism p ('Prod p1 q1)
- Konst :: forall b (p :: Poly). b -> Morphism p ('Const b)
- Depend :: forall a (p1 :: Poly) (q :: Poly). (a -> Morphism p1 q) -> Morphism ('Prod ('Const a) p1) q
- TensorAssocL :: forall (p1 :: Poly) (q1 :: Poly) (r :: Poly). Morphism ('Tensor ('Tensor p1 q1) r) ('Tensor p1 ('Tensor q1 r))
- TensorAssocR :: forall (p1 :: Poly) (q1 :: Poly) (r :: Poly). Morphism ('Tensor p1 ('Tensor q1 r)) ('Tensor ('Tensor p1 q1) r)
- TensorBraid :: forall (p1 :: Poly) (q1 :: Poly). Morphism ('Tensor p1 q1) ('Tensor q1 p1)
- ParT :: forall da a db b dc c dd d. Morphism (Mono da a) (Mono db b) -> Morphism (Mono dc c) (Mono dd d) -> Morphism ('Tensor (Mono da a) (Mono dc c)) ('Tensor (Mono db b) (Mono dd d))
- CompUnitL :: forall (q :: Poly). Netlist q => Morphism ('Comp 'Y q) q
- CompUnitL' :: forall (p :: Poly). Netlist p => Morphism p ('Comp 'Y p)
- CompUnitR :: forall (q :: Poly). Netlist q => Morphism ('Comp q 'Y) q
- CompUnitR' :: forall (p :: Poly). Netlist p => Morphism p ('Comp p 'Y)
- CompAssocL :: forall (p1 :: Poly) (q1 :: Poly) (r :: Poly). Morphism ('Comp ('Comp p1 q1) r) ('Comp p1 ('Comp q1 r))
- CompAssocR :: forall (p1 :: Poly) (q1 :: Poly) (r :: Poly). Morphism ('Comp p1 ('Comp q1 r)) ('Comp ('Comp p1 q1) r)
- CompT :: forall da a db b dc c dd d. Morphism (Mono da a) (Mono db b) -> Morphism (Mono dc c) (Mono dd d) -> Morphism ('Comp (Mono da a) (Mono dc c)) ('Comp (Mono db b) (Mono dd d))
- Prism :: forall s a. (s -> Either a s) -> (a -> s) -> Morphism ('Prod ('Const s) ('Exp s)) ('Sum (Mono a a) (Mono s s))
- lens :: (a -> b) -> (a -> db -> da) -> Morphism (Mono da a) (Mono db b)
- applyLens :: Morphism (Mono da a) (Mono db b) -> a -> (b, db -> da)
- prism :: (s -> Either a s) -> (a -> s) -> Morphism (Mono s s) ('Sum (Mono a a) (Mono s s))
- type family Pos (p :: Poly) where ...
- type family Dir (p :: Poly) where ...
- data Process a b where
- scan :: Process a b -> [a] -> [b]
- fold :: Process a b -> [a] -> Maybe b
- systemToProcess :: s -> (s -> b) -> System (->) s (Mono a b) -> Process a b
- markSystem :: (k -> Bool) -> (s -> b) -> System (->) s (Mono a b) -> System (->) (Either s s) (Mono (Boundary k a) (Maybe b))
- delay :: s -> Process s s
- register :: s -> Process (a, s) (b, s) -> Process a b
- mealy :: ch -> (ch -> a -> (ch, Maybe b)) -> Process a (Maybe b)
- runMealy :: Process a (Maybe b) -> [a] -> [b]
- newtype Out (arr :: k -> k1 -> Type) (a :: k1) = Out {}
- newtype In (arr :: k -> k1 -> Type) (a :: k) = In {}
- data Poles (arr :: k -> k1 -> Type) (a :: k) (b :: k1) = Poles {}
- close :: forall {k} arr (a :: k). In arr a -> Out arr a -> arr a a
- prefixIn :: forall {k} arr (a :: k) (b :: k). Category arr => arr a b -> In arr b -> In arr a
- suffixOut :: forall {k} arr (a :: k) (b :: k). Category arr => Out arr a -> arr a b -> Out arr b
- poles :: forall {k} arr (a :: k) (b :: k) (bot :: k). HasDual bot arr => arr a bot -> arr bot b -> Poles arr a b
- polesK :: Monad m => (a -> m ()) -> m b -> Poles (K m) a b
- splay :: forall {k} arr (a :: k) (b :: k) (bot :: k). HasDual bot arr => Poles arr a b -> (arr a bot, arr bot b)
- (>:>) :: forall {k} (arr :: k -> k -> Type) (a :: k) (b :: k) (c :: k) (bot :: k). HasDual bot arr => Poles arr a b -> Poles arr b c -> Poles arr a c
- class Category arr => HasDual (bot :: k) (arr :: k -> k -> Type) where
- copycat :: forall {k} (arr :: k -> k -> Type) (bot :: k). HasDual bot arr => Poles arr bot bot
- box :: forall {k} (bot :: k) arr (a :: k) (b :: k). HasDual bot arr => Poles arr a b -> arr a b
- boxAsymmetric :: forall {k} (bot :: k) (t :: k -> k -> k) arr (a :: k) (b :: k). (HasDual bot arr, Tensor t arr) => Poles arr a b -> arr (t a bot) (t bot b)
- data Free (arr :: k -> k -> Type) (a :: k) (b :: k)
- freeze :: forall {k} arr (a :: k) (b :: k). Category arr => Free arr a b -> arr a b
- class Layer (f :: Cat2 -> Cat2) where
- type Law (f :: Cat2 -> Cat2) (arr' :: Cat2)
- type Run (f :: Cat2 -> Cat2) (arr :: Cat2)
- type Bind (f :: Cat2 -> Cat2) (arr :: Cat2)
- unit :: forall (arr :: Type -> Type -> Type). Category arr => arr :~> f arr
- run :: (Run f arr, Law f arr, Bind f arr) => f arr a b -> arr a b
- bind :: forall arr' (arr :: Cat2) a b. (Law f arr', Bind f arr) => (arr :~> arr') -> f arr a b -> arr' a b
- type Cat2 = Type -> Type -> Type
- type (:~>) (arr :: k -> k1 -> Type) (arr' :: k -> k1 -> Type) = forall (x :: k) (y :: k1). arr x y -> arr' x y
- lower :: forall (f :: Cat2 -> Cat2) (arr :: Type -> Type -> Type) (arr' :: Type -> Type -> Type). (Layer f, Category arr) => (f arr :~> arr') -> arr :~> arr'
- (.>) :: forall {k} arr (a :: k) (b :: k) (c :: k). Category arr => arr a b -> arr b c -> arr a c
- (|>) :: a -> (a -> b) -> b
- (<|) :: (a -> b) -> a -> b
- class Copy (arr :: Type -> Type -> Type) a where
- copy :: arr a (a, a)
- class Discard (arr :: k -> Type -> Type) (a :: k) where
- discard :: arr a ()
- class Merge (arr :: Type -> Type -> Type) a where
- plus :: arr (a, a) a
- class Zero (arr :: Type -> k -> Type) (a :: k) where
- zero :: arr () a
- type CopyDiscard (arr :: Type -> Type -> Type) a = (Copy arr a, Discard arr a)
- type MergeZero (arr :: Type -> Type -> Type) a = (Merge arr a, Zero arr a)
- type Bimonoid (arr :: Type -> Type -> Type) a = (Copy arr a, Discard arr a, Merge arr a, Zero arr a)
- data Dagger (arr :: k -> k -> Type) (a :: k) (b :: k) = Dagger {}
- transpose :: forall {k} (arr :: k -> k -> Type) (a :: k) (b :: k). Dagger arr a b -> Dagger arr b a
- type SMC (w :: Type -> Type -> Type) (arr :: Type -> Type -> Type) = Syntax ((SigCompose :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPar w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: (SigSwap w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type))) arr
- type Net (w :: Type -> Type -> Type) (arr :: Type -> Type -> Type) = Syntax ((SigCompose :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPar w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigSwap w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigCopy w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigDiscard w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPlus w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: (SigZero w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type))))))) arr
- melt :: forall (w :: Type -> Type -> Type) (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) a b. (Traced t arr, Action w arr) => Net w arr a b -> Trace t arr a b
- newtype Pullback b a = Pullback {
- runPullback :: b -> a
- evalPullback :: Net (,) Pullback b a -> b -> a
- type Hyper = HyperA (->)
- newtype HyperA (arr :: Type -> k -> Type) (a :: k) (b :: k) = HyperA {}
- lift :: (a -> b) -> Hyper a b
- observe :: Hyper a b -> a -> b
- push :: (a -> b) -> Hyper a b -> Hyper a b
- runHyper :: Hyper a a -> a
- liftK :: forall (m :: Type -> Type) a b. Monad m => K m a b -> HyperA (K m) a b
- observeK :: Monad m => HyperA (K m) a b -> a -> m b
- pushK :: forall (m :: Type -> Type) a b. Monad m => K m a b -> HyperA (K m) a b -> HyperA (K m) a b
- runHyperK :: MonadFix m => HyperA (K m) a a -> m a
- encode :: Trace (,) (->) a b -> Hyper a b
- encodeK :: forall (m :: Type -> Type) a b. MonadFix m => Trace (,) (K m) a b -> HyperA (K m) a b
- encodeEither :: (Either a b -> Either a c) -> Hyper (Either a b -> c) (Either a b -> c)
- runEither :: (Either a b -> Either a c) -> b -> c
- superpose :: forall t (arr :: Type -> Type -> Type) a b c d. (Tensor t arr, Traced t arr) => Trace t arr a b -> Trace t arr c d -> Trace t arr (t a c) (t b d)
- data Stamped r a = Stamped {}
- data Bias
- type family Bot (p :: k -> k -> k) :: k
- class Category arr => Par (p :: k -> k -> k) (arr :: k -> k -> Type) where
- distL :: (a, Either b c) -> Either (a, b) c
- distR :: (Either b c, a) -> Either b (c, a)
- mix :: Void -> ()
- class Category arr => Lolli (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) where
- class Tensor t arr => Exponential (t :: k -> k -> k) (arr :: k -> k -> Type) where
- class Exponential t arr => BangCopy (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) where
- class Exponential t arr => BangWeaken (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) where
- class Exponential t arr => WhyNotIntro (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) where
- class (Exponential t arr, Par p arr) => WhyNotMonoid (t :: Type -> Type -> Type) (p :: Type -> Type -> Type) (arr :: Type -> Type -> Type) where
- type LinearBang (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) = (Exponential t arr, BangCopy t arr, BangWeaken t arr)
- type AffineBang (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) = (Exponential t arr, BangWeaken t arr)
- class Unital t arr => Tensor (t :: k -> k -> k) (arr :: k -> k -> Type) where
- tensor :: forall (a :: k) (b :: k) (c :: k) (d :: k). arr a b -> arr c d -> arr (t a c) (t b d)
- class Tensor t arr => Action (t :: k -> k -> k) (arr :: k -> k -> Type) where
- braid :: forall (a :: k) (b :: k). arr (t a b) (t b a)
- data Pick
- newtype Schedule s = Schedule {}
- class Tensor t arr => Shared (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) where
Trace (free traced category syntax)
type Trace (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) = Syntax ((SigCompose :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: (SigYank t :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type)) arr Source #
Free traced monoidal category over tensor t.
base :: forall arr a b (t :: Type -> Type -> Type). arr a b -> Trace t arr a b Source #
Lift a base arrow into the free traced category.
yank :: forall t (arr :: Type -> Type -> Type) s a b. Trace t arr (t s a) (t s b) -> Trace t arr a b Source #
Close a feedback loop over the channel tensor t.
class Strength t arr => Traced (t :: k -> k -> k) (arr :: k -> k -> Type) Source #
A trace over a morphism arr and tensor t.
trace closes the feedback loop, eliminating the tensor channel.
It extends the Strength structure with the feedback-fixing operation.
Object constraints on the feedback channel (a) used to let constrained
categories instance this class lawfully; those constraints are now
explicit at the instance site rather than inherited from a constraint
family.
Law note: the traced-category Sliding axiom is restricted in the
premonoidal setting. Benton & Hyland, "Traced Premonoidal Categories"
(2003, Def 3.2) replace unrestricted Sliding with Central Sliding:
a morphism g may slide past the trace only when g is central.
Dually, Centre Preservation says trace f is central whenever f is.
This class does not enforce the side-conditions at the type level; lawful
instances must guarantee them by construction. See the circuits-axioma
sliding oracles for witnesses that the side-condition is not vacuous.
Minimal complete definition
Instances
| Traced Either Process Source # | |
| Traced (,) Hyper Source # | |
| Traced (,) Process Source # | |
| Traced (,) Pullback Source # | The cartesian trace for pullbacks. The body is a linear map (dx, db) = f (dx, dc) solved by the same lazy knot that a differentiable arrow uses. For
strict carriers with nonzero channel self-coupling this diverges,
exactly as the lazy differentiable trace does. Unlike the differentiable
case, though, the equation here is always affine —
|
| (Category arr, Traced t arr) => Traced (t :: Type -> Type -> Type) (AlgCat arr :: Type -> Type -> Type) Source # | |
| Traced Either (K IO) Source # | Traced for Each iteration re-establishes the prompt boundary. When
|
| Monad m => Traced Either (K m :: Type -> Type -> Type) Source # | |
| Traced Either (->) Source # | The Either trace iterates:
Vanishing (a): tracing over the unit does nothing. The unit is
Yanking: tracing a braid is the identity.
Tightening: payload morphisms pass freely through the trace.
|
| MonadFix m => Traced (,) (K m :: Type -> Type -> Type) Source # | |
| MonadFix m => Traced (,) (HyperA (K m) :: Type -> Type -> Type) Source # | |
| Traced (,) (->) Source # | The cartesian trace ties a lazy knot: the feedback value Only works in a lazy setting — the feedback value is a self-referential thunk. In a strict language this binding is circular and divergent. Haskell's lazy evaluation makes cyclic sharing possible without an explicit fixpoint operator.
Vanishing (a): tracing over the unit does nothing. The unit is
Yanking: tracing a braid is the identity.
Tightening: payload morphisms pass freely through the trace.
Sliding: a morphism on the channel slides from one side to the other.
Strength: an independent payload wire is invisible to the trace.
|
Defined in Circuit.Channel | |
| (Traced t arr, Action w arr) => Traced (t :: Type -> Type -> Type) (SMC w arr :: Type -> Type -> Type) Source # | |
| Traced t arr => Traced (t :: Type -> Type -> Type) (Trace t arr :: Type -> Type -> Type) Source # | |
| Traced t arr => Traced (t :: k -> k -> k) (Dagger arr :: k -> k -> Type) Source # | |
| Traced t arr => Traced (t :: k -> k -> k) (Free arr :: k -> k -> Type) Source # | Lift the A loop body in |
class Channel t arr => Strength (t :: k -> k -> k) (arr :: k -> k -> Type) Source #
Tensorial strength for a tensor t inside a category arr.
strength tensors a plain morphism with the ambient channel. It is
not a syntactic inverse of trace; it is the strength
("tensorial strength") of the tensor t acting on morphisms.
Minimal complete definition
Instances
| Strength Either Process Source # | |
| Strength (,) Hyper Source # | |
| Strength (,) Process Source # | |
| Strength (,) Pullback Source # | |
| (Category arr, Strength t arr) => Strength (t :: Type -> Type -> Type) (AlgCat arr :: Type -> Type -> Type) Source # | |
| Monad m => Strength Either (K m :: Type -> Type -> Type) Source # | Traced for Iterates by feeding
This instance is |
| Strength Either (->) Source # | Either tensorial strength for |
| Monad m => Strength These (K m :: Type -> Type -> Type) Source # | Inclusive tensorial strength for |
| Strength These (->) Source # | Inclusive tensorial strength for
|
| Monad m => Strength (,) (K m :: Type -> Type -> Type) Source # | Traced for The lazy knot is tied via
|
| Monad m => Strength (,) (HyperA (K m) :: Type -> Type -> Type) Source # | |
| Strength (,) (->) Source # | Cartesian tensorial strength for The implementation uses explicit projections so that the result pair
constructor exists before the feedback channel is forced; this keeps
fused
|
Defined in Circuit.Channel | |
| (Strength t arr, Action w arr) => Strength (t :: Type -> Type -> Type) (SMC w arr :: Type -> Type -> Type) Source # | |
| (Strength t arr, Traced t arr) => Strength (t :: Type -> Type -> Type) (Trace t arr :: Type -> Type -> Type) Source # | |
| Strength t arr => Strength (t :: k -> k -> k) (Dagger arr :: k -> k -> Type) Source # | |
| Strength t arr => Strength (t :: k -> k -> k) (Free arr :: k -> k -> Type) Source # | Lift the A morphism is frozen before tensoring with the feedback channel. |
Close a feedback loop. See Circuit.Channel.
Open a feedback loop. See Circuit.Channel.
strength :: forall (b :: k) (c :: k) (a :: k). Strength t arr => arr b c -> arr (t a b) (t a c) Source #
Polynomial channels
data Channel (arr :: Type -> Type -> Type) (p :: Poly) where Source #
A channel whose interface is the polynomial p.
Internally it is a Moore system with hidden state s. The state is
existentially quantified so that different channel constructors can use
different state types.
emitChannel :: forall (p :: Poly). Channel (->) p -> Eval p () Source #
Observe the current output of a (->) channel.
The observation is an Eval p (): a position together with a trivial
direction consumer. The position is the channel's current output; the
direction consumer is how a future input will advance the channel.
commitChannel :: forall (p :: Poly). Channel (->) p -> Dir p -> Channel (->) p Source #
Commit an input direction to a (->) channel, advancing its state.
idChannel :: a -> Channel (->) (Mono a a) Source #
Identity channel on a monomial interface Mono a a.
Output is the current state; next state is the input direction. An initial state must be supplied because a Moore machine has no input before the first commit.
constChannel :: b -> Channel (->) (Mono a b) Source #
Constant-output channel on a monomial interface Mono a b.
Output is always b; the state is the constant value and is preserved
across commits (the input direction is ignored).
mapChannel :: forall (p :: Poly) (q :: Poly). (SystemEval p, SystemEval q) => Morphism p q -> Channel (->) p -> Channel (->) q Source #
Map a polynomial morphism over a (->) channel.
The forward map transforms positions; the backward map transforms
directions. This is the functorial action of Morphism on
channels.
Body (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 |
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.
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.
Circ (loose bicategory of bodies with varying carriers)
data Circ (t :: k -> k1 -> k2) (arr :: k2 -> k2 -> Type) (a :: k1) (b :: k1) where Source #
Loose 1-cell: a body with its carrier type hidden.
Constructors
| Circ :: forall {k} {k1} {k2} (t :: k -> k1 -> k2) (ch :: k) (arr :: k2 -> k2 -> Type) (a :: k1) (b :: k1). Body t ch arr a b -> Circ t arr a b |
idCirc :: forall {k2} (t :: k2 -> k2 -> k2) (arr :: k2 -> k2 -> Type) (a :: k2). Strength t arr => Circ t arr a a Source #
Identity loose 1-cell at the tensor unit carrier.
The carrier is pinned to Unit so that the unit law can be witnessed with
the unitor; without the annotation GHC would instantiate the hidden carrier
to Any.
data Sq (t :: k2 -> k1 -> k2) (arr :: k2 -> k2 -> Type) (ch :: k2) (ch' :: k2) (a :: k1) (b :: k1) Source #
Square (indexed 2-cell). The carrier maps compose; the middle body must match (a caller side condition).
idSq :: forall {k2} {k1} (arr :: k2 -> k2 -> Type) (t :: k2 -> k1 -> k2) (ch :: k2) (a :: k1) (b :: k1). Category arr => Body t ch arr a b -> Sq t arr ch ch a b Source #
Identity square on a body.
vcomp :: forall {k2} {k1} (arr :: k2 -> k2 -> Type) (t :: k2 -> k1 -> k2) (ch' :: k2) (ch'' :: k2) (a :: k1) (b :: k1) (ch :: k2). Category arr => Sq t arr ch' ch'' a b -> Sq t arr ch ch' a b -> Sq t arr ch ch'' a b Source #
Vertical composition of squares.
The middle body must match; this is a caller side condition.
data Intertwiner (t :: k2 -> k1 -> k2) (arr :: k2 -> k2 -> Type) (a :: k1) (b :: k1) where Source #
Existential closure of Sq, for stating "there exists a 2-cell".
Constructors
| Intertwiner :: forall {k2} {k1} (t :: k2 -> k1 -> k2) (arr :: k2 -> k2 -> Type) (ch :: k2) (ch' :: k2) (a :: k1) (b :: k1). Sq t arr ch ch' a b -> Intertwiner t arr a b |
withIntertwiner :: forall {k2} {k1} (t :: k2 -> k1 -> k2) (arr :: k2 -> k2 -> Type) (a :: k1) (b :: k1) r. Intertwiner t arr a b -> (forall (ch :: k2) (ch' :: k2). Sq t arr ch ch' a b -> r) -> r Source #
Eliminator for the existential carrier types of an Intertwiner.
downThenAcross :: forall {k1} (t :: k1 -> k1 -> k1) arr (ch :: k1) (ch' :: k1) (a :: k1) (b :: k1). Tensor t arr => Sq t arr ch ch' a b -> arr (t ch a) (t ch' b) Source #
Go down (carrier map) then across (target body).
A nondegenerate intertwiner witness: counter state quotiented by parity.
The payload is Char so the carrier slot and payload slot are type-distinct;
slot confusion is a type error. These examples exercise both parities and
both reset branches. A paired perturbation doctest on acrossThenDown
shows the equality can fail, so these agreement cases are not vacuous.
>>>let counter = (Body $ \(n, r) -> let n' = if r then 0 else n + 1 in (n', if odd n' then 'x' else 'y')) :: Body (,) Int (->) Bool Char>>>let parity = (Body $ \(b, r) -> let b' = not r && not b in (b', if b' then 'x' else 'y')) :: Body (,) Bool (->) Bool Char>>>let sq = Sq odd counter parity :: Sq (,) (->) Int Bool Bool Char>>>downThenAcross sq (4, False)(True,'x')>>>downThenAcross sq (4, True)(False,'y')>>>downThenAcross sq (5, False)(False,'y')
acrossThenDown :: forall {k1} (t :: k1 -> k1 -> k1) arr (ch :: k1) (ch' :: k1) (a :: k1) (b :: k1). Tensor t arr => Sq t arr ch ch' a b -> arr (t ch a) (t ch' b) Source #
Go across (source body) then down (carrier map).
Agreement cases for the same witness:
>>>let counter = (Body $ \(n, r) -> let n' = if r then 0 else n + 1 in (n', if odd n' then 'x' else 'y')) :: Body (,) Int (->) Bool Char>>>let parity = (Body $ \(b, r) -> let b' = not r && not b in (b', if b' then 'x' else 'y')) :: Body (,) Bool (->) Bool Char>>>let sq = Sq odd counter parity :: Sq (,) (->) Int Bool Bool Char>>>acrossThenDown sq (4, False)(True,'x')>>>acrossThenDown sq (4, True)(False,'y')>>>acrossThenDown sq (5, False)(False,'y')
Perturbation: observe even-ness instead of odd-ness. The two paths now disagree, which proves the agreement cases above are not vacuous.
>>>let badCounter = (Body $ \(n, r) -> let n' = if r then 0 else n + 1 in (n', if even n' then 'x' else 'y')) :: Body (,) Int (->) Bool Char>>>let bad = Sq odd badCounter parity :: Sq (,) (->) Int Bool Bool Char>>>downThenAcross bad (4, False)(True,'x')>>>acrossThenDown bad (4, False)(True,'y')
cascade :: forall {k2} (t :: k2 -> k2 -> k2) (arr :: k2 -> k2 -> Type) (b :: k2) (c :: k2) (a :: k2). Strength t arr => Circ t arr b c -> Circ t arr a b -> Circ t arr a c Source #
Carrier-tensoring composition of loose 1-cells.
The composite has carrier t ch ch' when the first body has carrier ch
and the second has carrier ch'.
unitorLeft :: forall {k1} (t :: k1 -> k1 -> k1) (arr :: k1 -> k1 -> Type) (ch :: k1) (a :: k1) (b :: k1). (Unital t arr, Strength t arr) => Body t ch arr a b -> Intertwiner t arr a b Source #
Left unitor witness: composing a body with the identity at the unit carrier is isomorphic to the original body.
unitorRight :: forall {k1} (t :: k1 -> k1 -> k1) (arr :: k1 -> k1 -> Type) (ch :: k1) (a :: k1) (b :: k1). (Unital t arr, Strength t arr) => Body t ch arr a b -> Intertwiner t arr a b Source #
Right unitor witness.
unitorLeftSq :: forall {k} (t :: k -> k -> k) (arr :: k -> k -> Type) (ch :: k) (a :: k) (b :: k). (Unital t arr, Strength t arr) => Body t ch arr a b -> Sq t arr (t (Unit t) ch) ch a b Source #
Indexed left unitor square.
unitorRightSq :: forall {k} (t :: k -> k -> k) (arr :: k -> k -> Type) (ch :: k) (a :: k) (b :: k). (Unital t arr, Strength t arr) => Body t ch arr a b -> Sq t arr (t ch (Unit t)) ch a b Source #
Indexed right unitor square.
associator :: forall {k1} (t :: k1 -> k1 -> k1) (arr :: k1 -> k1 -> Type) (ch3 :: k1) (c :: k1) (d :: k1) (ch2 :: k1) (b :: k1) (ch1 :: k1) (a :: k1). Strength t arr => Body t ch3 arr c d -> Body t ch2 arr b c -> Body t ch1 arr a b -> Intertwiner t arr a d Source #
Associator witness: carrier bracketing of three composed bodies is isomorphic up to the associator of the tensor.
associatorSq :: forall {k1} (t :: k1 -> k1 -> k1) (arr :: k1 -> k1 -> Type) (ch3 :: k1) (c :: k1) (d :: k1) (ch2 :: k1) (b :: k1) (ch1 :: k1) (a :: k1). Strength t arr => Body t ch3 arr c d -> Body t ch2 arr b c -> Body t ch1 arr a b -> Sq t arr (t (t ch1 ch2) ch3) (t ch1 (t ch2 ch3)) a d Source #
Indexed associator square.
rightWhisker :: forall {k1} (t :: k1 -> k1 -> k1) (arr :: k1 -> k1 -> Type) (ch :: k1) (ch' :: k1) (a :: k1) (b :: k1) (d :: k1) (c :: k1). (Tensor t arr, Strength t arr) => Sq t arr ch ch' a b -> Body t d arr b c -> Sq t arr (t ch d) (t ch' d) a c Source #
Right whisker: tensor a square with an identity-on-boundaries 1-cell on the right.
leftWhisker :: forall {k1} (t :: k1 -> k1 -> k1) (arr :: k1 -> k1 -> Type) (d :: k1) (a' :: k1) (a :: k1) (ch :: k1) (ch' :: k1) (b :: k1). (Tensor t arr, Strength t arr) => Body t d arr a' a -> Sq t arr ch ch' a b -> Sq t arr (t d ch) (t d ch') a' b Source #
Left whisker: tensor an identity-on-boundaries 1-cell on the left of a square.
hcompose :: forall {k1} (t :: k1 -> k1 -> k1) (arr :: k1 -> k1 -> Type) (ch2 :: k1) (ch2' :: k1) (b :: k1) (c :: k1) (ch1 :: k1) (ch1' :: k1) (a :: k1). (Tensor t arr, Strength t arr) => Sq t arr ch2 ch2' b c -> Sq t arr ch1 ch1' a b -> Sq t arr (t ch1 ch2) (t ch1' ch2') a c Source #
Horizontal composition of two squares.
whiskerSq :: forall {k1} (t :: k1 -> k1 -> k1) arr (a' :: k1) (a :: k1) (b :: k1) (b' :: k1) (ch :: k1) (ch' :: k1). Tensor t arr => arr a' a -> arr b b' -> Sq t arr ch ch' a b -> Sq t arr ch ch' a' b' Source #
Boundary whisker: apply tight maps to the input and output boundaries of a
square. This is the Sq side of the interchange law; the Poles side is
iomap on the Moore-split representation.
Feedback on Circ
feedback :: forall {k2} (t :: k2 -> k2 -> k2) (arr :: k2 -> k2 -> Type) (s :: k2) (a :: k2) (b :: k2). Channel t arr => Circ t arr (t s a) (t s b) -> Circ t arr a b Source #
Close a feedback loop over a component s of the input/output object.
The 1-cell must be of the form Circ t arr (t s a) (t s b): the feedback
value s appears as the first component of the tensor in both domain and
codomain. The result moves s into the hidden carrier, turning it into
state. This is the guarded / state-bootstrapping feedback of KSW, not the
immediate fixed-point trace: yanking fails here, which is the expected
behaviour for a feedback category.
Implemented by reassociating so that s becomes part of the carrier:
feedback (Circ (Body f)) = Circ (Body (assoc .> f .> assoc'))
Polynomial interfaces
system :: forall arr s (p :: Poly). arr (s, Dir p) (s, Pos p) -> System arr s p Source #
Construct a cartesian System from its underlying arrow.
runSystem :: forall arr s (p :: Poly). System arr s p -> arr (s, Dir p) (s, Pos p) Source #
Inspect a cartesian System as its underlying arrow.
mooreSystem :: (s -> a -> s) -> (s -> b) -> System (->) s (Mono a b) Source #
Build a monomial System from a step and an observation.
This is the pointed-Moore view of a stateful morphism, expressed directly
in System terminology. The state transition s -> a -> s and the
observation s -> b are explicit; the seed is supplied later (for example
by systemToProcess).
type Mono i o = 'Prod ('Const o) ('Exp i) Source #
The monomial interface: i directions (input), o positions (output).
data Morphism (p :: Poly) (q :: Poly) where Source #
A morphism p -> q in Poly, encoded as a natural transformation
between the evaluated functors.
By the Yoneda / sigma universal property, this is equivalent to a bundle map: a function on positions together with a contravariant family of functions on directions.
Konst and Depend extend the original Poly sketch so that backward
maps can depend on the current position, giving point-dependent lenses.
Constructors
| Id :: forall (p :: Poly). Morphism p p | Identity morphism. |
| Point :: forall (q :: Poly). Eval q () -> Morphism 'Y q | Global element: a point of By the Yoneda lemma, |
| ConstMap :: forall a b. (a -> b) -> Morphism ('Const a) ('Const b) | Covariant embedding of a plain function into constants. |
| ExpMap :: forall a b. (a -> b) -> Morphism ('Exp b) ('Exp a) | Contravariant embedding of a plain function into exponentials. |
| Compose :: forall (q1 :: Poly) (q :: Poly) (p :: Poly). Morphism q1 q -> Morphism p q1 -> Morphism p q | Sequential composition. |
| Par :: forall (p1 :: Poly) (p' :: Poly) (q1 :: Poly) (q' :: Poly). Morphism p1 p' -> Morphism q1 q' -> Morphism ('Prod p1 q1) ('Prod p' q') | Parallel composition (cartesian product of morphisms). |
| Inl :: forall (p :: Poly) (q1 :: Poly). Morphism p ('Sum p q1) | Coproduct injections. |
| Inr :: forall (p :: Poly) (p1 :: Poly). Morphism p ('Sum p1 p) | |
| Case :: forall (p1 :: Poly) (q :: Poly) (q1 :: Poly). Morphism p1 q -> Morphism q1 q -> Morphism ('Sum p1 q1) q | Coproduct case analysis. |
| Fst :: forall (q :: Poly) (q1 :: Poly). Morphism ('Prod q q1) q | Product projections. |
| Snd :: forall (p1 :: Poly) (q :: Poly). Morphism ('Prod p1 q) q | |
| Pair :: forall (p :: Poly) (p1 :: Poly) (q1 :: Poly). Morphism p p1 -> Morphism p q1 -> Morphism p ('Prod p1 q1) | Product pairing. |
| Konst :: forall b (p :: Poly). b -> Morphism p ('Const b) | Global element (constant introduction). |
| Depend :: forall a (p1 :: Poly) (q :: Poly). (a -> Morphism p1 q) -> Morphism ('Prod ('Const a) p1) q | Copower universal property: a |
| TensorAssocL :: forall (p1 :: Poly) (q1 :: Poly) (r :: Poly). Morphism ('Tensor ('Tensor p1 q1) r) ('Tensor p1 ('Tensor q1 r)) | Left associator for the Dirichlet tensor:
|
| TensorAssocR :: forall (p1 :: Poly) (q1 :: Poly) (r :: Poly). Morphism ('Tensor p1 ('Tensor q1 r)) ('Tensor ('Tensor p1 q1) r) | Right associator for the Dirichlet tensor. |
| TensorBraid :: forall (p1 :: Poly) (q1 :: Poly). Morphism ('Tensor p1 q1) ('Tensor q1 p1) | Symmetry/braiding for the Dirichlet tensor: |
| ParT :: forall da a db b dc c dd d. Morphism (Mono da a) (Mono db b) -> Morphism (Mono dc c) (Mono dd d) -> Morphism ('Tensor (Mono da a) (Mono dc c)) ('Tensor (Mono db b) (Mono dd d)) | Functorial action of the Dirichlet tensor on monomial morphisms:
Restricted to monomials because the current |
| CompUnitL :: forall (q :: Poly). Netlist q => Morphism ('Comp 'Y q) q | Left unitor for the composition product: |
| CompUnitL' :: forall (p :: Poly). Netlist p => Morphism p ('Comp 'Y p) | Inverse left unitor for the composition product. |
| CompUnitR :: forall (q :: Poly). Netlist q => Morphism ('Comp q 'Y) q | Right unitor for the composition product: |
| CompUnitR' :: forall (p :: Poly). Netlist p => Morphism p ('Comp p 'Y) | Inverse right unitor for the composition product. |
| CompAssocL :: forall (p1 :: Poly) (q1 :: Poly) (r :: Poly). Morphism ('Comp ('Comp p1 q1) r) ('Comp p1 ('Comp q1 r)) | Left associator for the composition product:
|
| CompAssocR :: forall (p1 :: Poly) (q1 :: Poly) (r :: Poly). Morphism ('Comp p1 ('Comp q1 r)) ('Comp ('Comp p1 q1) r) | Right associator for the composition product. |
| CompT :: forall da a db b dc c dd d. Morphism (Mono da a) (Mono db b) -> Morphism (Mono dc c) (Mono dd d) -> Morphism ('Comp (Mono da a) (Mono dc c)) ('Comp (Mono db b) (Mono dd d)) | Functorial action of the composition product on monomial morphisms:
Restricted to monomials for the same reason as |
| Prism :: forall s a. (s -> Either a s) -> (a -> s) -> Morphism ('Prod ('Const s) ('Exp s)) ('Sum (Mono a a) (Mono s s)) | Prism: a co-lens that matches on a sum-like position. Forward pass |
lens :: (a -> b) -> (a -> db -> da) -> Morphism (Mono da a) (Mono db b) Source #
The general point-dependent lens.
Forward pass get :: a -> b; backward pass put :: a -> db -> da
depends on the current position.
>>>let l = lens show (\n d -> n + d) :: Morphism (Mono Int Int) (Mono Int String)>>>let (v, put) = applyLens l 40 in (v, put 2)("40",42)
applyLens :: Morphism (Mono da a) (Mono db b) -> a -> (b, db -> da) Source #
Apply a monomial morphism as a lens: (get, put).
prism :: (s -> Either a s) -> (a -> s) -> Morphism (Mono s s) ('Sum (Mono a a) (Mono s s)) Source #
Prism: match on a sum-like source, build from the focused branch.
>>>let p = prism (\case Left n -> Left n; Right s -> Right (Right s)) Left :: Morphism (Mono (Either Int String) (Either Int String)) ('Sum (Mono Int Int) (Mono (Either Int String) (Either Int String)))>>>case runMorphism p (EP (EK (Left 7), EE id)) of ES (Left (EP (EK n, EE k))) -> (n, k 1)(7,Left 1)
type family Pos (p :: Poly) where ... Source #
Position set of a polynomial.
For a value of p(x), 'Pos p' is the index type of positions.
type family Dir (p :: Poly) where ... Source #
Direction set of a polynomial.
For a value of p(x) at a given position, 'Dir p' is the domain of the
function into x.
Sum gets a flat direction space . This
is an over-approximation: only the branch selected by the position is
in-fibre. It is nonetheless the right shape for dynamics, where the
input direction is supplied after the position is observed: a wrong-branch
direction is simply off-fibre. The netlist view (Either (Dir p) (Dir q)Netlist) remains
position-dependent and still does not admit a Sum instance.
For Comp, is the same flat
approximation: the Dir ('Comp p q) = ('Dir p, 'Dir q)q-position (hence its honest pin set) depends on which
p-direction was taken. Exact for Sum-free factors with uniform
directions — the monomial fragment.
Stream transformer (first-input-seeded processes)
data Process a b where Source #
A stateful process from a to b.
The existential state type s is hidden; the observable interface is the
triple inject step extract. Keeping the triple as the primitive (rather
than fusing extract into the step) preserves the streaming-statistics
invariant that the first output is extract (inject x), before any step.
Instances
| Copy (->) a => Copy Process a Source # | |
Defined in Circuit.Process | |
| Merge (->) a => Merge Process a Source # | |
Defined in Circuit.Process | |
| Category Process Source # | |
| Shared (,) Process Source # | Cartesian shared fusion on processes. The two processes share one feedback channel |
| Discard Process (a :: Type) Source # | |
Defined in Circuit.Process | |
| Zero (->) a => Zero Process (a :: Type) Source # | |
Defined in Circuit.Process | |
| Channel Either Process Source # | |
| Channel (,) Process Source # | |
| Strength Either Process Source # | |
| Strength (,) Process Source # | |
| Traced Either Process Source # | |
| Traced (,) Process Source # | |
| Action (,) Process Source # | |
Defined in Circuit.Process | |
| Tensor (,) Process Source # | |
| Unital (,) Process Source # | |
scan :: Process a b -> [a] -> [b] Source #
List specialization of scanStream.
markSystem :: (k -> Bool) -> (s -> b) -> System (->) s (Mono a b) -> System (->) (Either s s) (Mono (Boundary k a) (Maybe b)) Source #
Lift a monomial System and a state observation into a boundary system
over Boundary tokens.
Payloads are stepped through the inner system. Marks satisfying the halt
predicate freeze the system and produce Nothing thereafter; non-halt
marks leave the state unchanged and emit the current output. The halted
state remembers the final inner state.
The returned system carries state Either s s: Left is running, Right
is halted. This is the core combinator behind mark-driven halt: the finite
mark alphabet k carries control tokens, while payloads carry data.
delay :: s -> Process s s Source #
One-tick delay with an initial value.
Output is s0 on the first tick and the input from the previous tick
thereafter. This is the primitive that makes register productive: the
feedback wire is observable one tick late.
register :: s -> Process (a, s) (b, s) -> Process a b Source #
Cross-tick register feedback.
Given an initial feedback value s0 and a process Process (a, s) (b, s),
close the s wire so that the s produced at one tick is fed back as
input at the next tick. This is the productive, strict-accumulator-safe
analogue of the cartesian trace: the delay is explicit in the wiring
rather than implicit in a lazy knot.
Compare with the cartesian trace on Process, which ties a lazy knot
and diverges for strict state; register keeps strict state cells sound
by making the one-tick delay observable.
For bodies whose fixed-point is independent of the initial feedback value
(e.g. affine/stateless feedback such as ewmaBody), the same wiring can
be expressed by swapping the feedback wire into the active position,
applying strength (delay s0), and tracing.
Channel poles (bi-polar effectful/process API; still the right tool for
newtype Out (arr :: k -> k1 -> Type) (a :: k1) Source #
Out is the companion of the identity functor. Covariant in a
(sits in the output position).
newtype In (arr :: k -> k1 -> Type) (a :: k) Source #
In is the conjoint of the identity functor. Contravariant in
a (sits in the input position).
data Poles (arr :: k -> k1 -> Type) (a :: k) (b :: k1) Source #
A matched pair of channel poles: one In and one Out.
This is the bi-polar communication contract. The conjoint (In)
consumes payloads of type a; the companion (Out) produces payloads
of type b. For symmetric channels such as queues a = b.
Together with prefixIn and suffixOut, Poles carries an enriched
profunctor structure over the base category arr: prefixIn is the
left action of arr on In poles, and suffixOut is the right action
of arr on Out poles.
prefixIn :: forall {k} arr (a :: k) (b :: k). Category arr => arr a b -> In arr b -> In arr a Source #
Precompose an arr-morphism with an In pole.
Given f :: arr a b and an In pole at type b, produce an In pole
at type a. Running the resulting pole first executes f and then
commits through the original pole.
This is the left (contravariant) action of the base category on In
poles. Specialised to unit poles it is the canonical way to build
effectful write poles.
>>>let polesU = open :: Poles (->) () ()>>>let inA = prefixIn (const ()) (conjoint polesU) :: In (->) Int>>>commit inA (companion polesU) 42()
suffixOut :: forall {k} arr (a :: k) (b :: k). Category arr => Out arr a -> arr a b -> Out arr b Source #
Postcompose an arr-morphism with an Out pole.
Given an Out pole at type a and g :: arr a b, produce an Out
pole at type b. Running the resulting pole first emits through the
original pole and then executes g on the emitted value.
This is the right (covariant) action of the base category on Out
poles. Specialised to unit poles it is the canonical way to build
effectful read poles.
>>>let polesU = open :: Poles (->) () ()>>>let outA = suffixOut (companion polesU) (const 42) :: Out (->) Int>>>emit outA (conjoint polesU) ()42
poles :: forall {k} arr (a :: k) (b :: k) (bot :: k). HasDual bot arr => arr a bot -> arr bot b -> Poles arr a b Source #
Build a Poles from a write morphism and a read morphism.
write :: arr a bot consumes the input payload and produces the dualising
object; read :: arr bot b consumes the dualising object and produces the
output payload. The dualising-object poles wire the two halves together.
This is the canonical way to turn a pair of primitive channel actions
into a matched pair of In and Out poles.
Compositional spelling:
poles write receive = Poles (prefixIn write (conjoint open)) (suffixOut (companion open) receive)
polesK :: Monad m => (a -> m ()) -> m b -> Poles (K m) a b Source #
Specialization of poles for K actions.
write :: a -> m () consumes the input payload; receive :: m b
produces the output payload. The dualising-object handling is hidden
inside the K wrappers.
splay :: forall {k} arr (a :: k) (b :: k) (bot :: k). HasDual bot arr => Poles arr a b -> (arr a bot, arr bot b) Source #
Extract the primitive write and read actions from a Poles by
plugging each pole with the dualising-object poles.
For a Poles built with poles, this recovers the original
write :: arr a bot and receive :: arr bot b.
>>>let p = poles0 (\() -> ()) (const (42 :: Int)) :: Poles (->) () Int>>>let (write, receive) = splay0 p>>>(write (), receive ())((),42)
(>:>) :: forall {k} (arr :: k -> k -> Type) (a :: k) (b :: k) (c :: k) (bot :: k). HasDual bot arr => Poles arr a b -> Poles arr b c -> Poles arr a c infixr 1 Source #
Forward-composition operator for Poles. p1 >:> p2 = compose p1 p2.
class Category arr => HasDual (bot :: k) (arr :: k -> k -> Type) where Source #
Arrows that have channel poles for a given dualising object bot.
The dualising object is the target of the polar pairing and the object
through which the two poles of a Poles are plugged together. In the
cartesian case it is the monoidal unit (); for halt-mark / delivery
pairings it can be Bool.
The poles are the identity-on-bot morphism split into its two polar
halves. The companion is constant; the conjoint delegates to the
opposing companion.
These poles require the base arrow to support constant morphisms, so they are captured by this class rather than being definable for all arrows.
Methods
open :: Poles arr bot bot Source #
The dualising object as channel poles.
Yank
>>>let poles = open :: Poles (->) () ()>>>close (conjoint poles) (companion poles) ()()
Plug
>>>let polesA = open :: Poles (->) () ()>>>let polesU = open :: Poles (->) () ()>>>commit (conjoint polesA) (companion polesU) ()()>>>emit (companion polesA) (conjoint polesU) ()()
Instances
| Monad m => HasDual () (K m :: Type -> Type -> Type) Source # | Dualising object Same shape as the |
| HasDual () (->) Source # | Dualising object The companion is the constant function returning |
Defined in Circuit.Poles | |
| Monad m => HasDual Bool (K m :: Type -> Type -> Type) Source # | Dualising object Same shape as the |
| HasDual Bool (->) Source # | Dualising object The companion is the constant function returning |
| (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 |
Copycat / multiplicative excluded middle
copycat :: forall {k} (arr :: k -> k -> Type) (bot :: k). HasDual bot arr => Poles arr bot bot Source #
The copycat strategy at the dualising object bot.
This is the multiplicative excluded middle bot ⅋ bot⊥ for arrows that
have poles at bot: a self-dual channel whose close is the identity on
bot. It routes between the two poles without ever deciding which one
holds.
The additive excluded middle bot ⊕ bot⊥ — a verdict, now — is not
supported; there is no decide :: Either bot bot here, because only the
routing witness is provable.
Boxes
box :: forall {k} (bot :: k) arr (a :: k) (b :: k). HasDual bot arr => Poles arr a b -> arr a b Source #
Close a Poles to a plain base-arrow morphism.
A matched pair of free poles (Poles) is a box with one input wire and
one output wire. This helper embeds that box into a traced monoidal
category by unit-plugging the remaining two slots, giving a plain
arr a b: input on the left, output on the right, with the unit plumbing
hidden.
>>>let p = poles0 (const ()) (const 42) :: Poles (->) () Int>>>box @() p ()42
boxAsymmetric :: forall {k} (bot :: k) (t :: k -> k -> k) arr (a :: k) (b :: k). (HasDual bot arr, Tensor t arr) => Poles arr a b -> arr (t a bot) (t bot b) Source #
Asymmetric box with the dualising object exposed on opposite sides.
Uses tensor at the base arrow level. The input carries the dualising object
on the right and the output carries it on the left; most users will prefer
the dualising-object-normalised box.
>>>let p = poles0 (const ()) (const 42) :: Poles (->) () Int>>>boxAsymmetric @() p ((), ())((),42)
Free
data Free (arr :: k -> k -> Type) (a :: k) (b :: k) Source #
The free category over a base arrow.
The two constructors are Lift, which embeds a base arrow, and
Compose, which sequences two free morphisms. The universal fold out
of Free is run.
>>>run (Lift (+1) :: Free (->) Int Int) 56>>>run (Compose (Lift (+1)) (Lift (*2)) :: Free (->) Int Int) 511
Instances
| Channel t arr => Channel (t :: k -> k -> k) (Free arr :: k -> k -> Type) Source # | |||||||||||||
Defined in Circuit.Layer | |||||||||||||
| Strength t arr => Strength (t :: k -> k -> k) (Free arr :: k -> k -> Type) Source # | Lift the A morphism is frozen before tensoring with the feedback channel. | ||||||||||||
| Traced t arr => Traced (t :: k -> k -> k) (Free arr :: k -> k -> Type) Source # | Lift the A loop body in | ||||||||||||
| Category arr => Category (Free arr :: k -> k -> Type) Source # | |||||||||||||
| Layer (Free :: (Type -> Type -> Type) -> Type -> Type -> Type) Source # | Layer instance for the free category. Without object constraints, folding is just recursive application of the target category's composition. | ||||||||||||
Defined in Circuit.Layer Associated Types
Methods unit :: forall (arr :: Type -> Type -> Type). Category arr => arr :~> Free arr Source # run :: (Run (Free :: (Type -> Type -> Type) -> Type -> Type -> Type) arr, Law (Free :: (Type -> Type -> Type) -> Type -> Type -> Type) arr, Bind (Free :: (Type -> Type -> Type) -> Type -> Type -> Type) arr) => Free arr a b -> arr a b Source # bind :: forall arr' (arr :: Cat2) a b. (Law (Free :: (Type -> Type -> Type) -> Type -> Type -> Type) arr', Bind (Free :: (Type -> Type -> Type) -> Type -> Type -> Type) arr) => (arr :~> arr') -> Free arr a b -> arr' a b Source # | |||||||||||||
| type Bind (Free :: (Type -> Type -> Type) -> Type -> Type -> Type) arr Source # | |||||||||||||
| type Law (Free :: (Type -> Type -> Type) -> Type -> Type -> Type) arr' Source # | |||||||||||||
| type Run (Free :: (Type -> Type -> Type) -> Type -> Type -> Type) arr Source # | |||||||||||||
Layer tower
class Layer (f :: Cat2 -> Cat2) where Source #
A free construction over a base arrow.
Associated Types
type Law (f :: Cat2 -> Cat2) (arr' :: Cat2) Source #
What the target category must satisfy to receive a bind fold.
run only needs the base category's own structure.
type Run (f :: Cat2 -> Cat2) (arr :: Cat2) Source #
What the base category must satisfy to receive a run fold back into
itself. Defaults to no extra constraints.
type Bind (f :: Cat2 -> Cat2) (arr :: Cat2) Source #
Extra constraints the source category must satisfy for a bind
fold. Defaults to no extra constraints.
Methods
unit :: forall (arr :: Type -> Type -> Type). Category arr => arr :~> f arr Source #
Include a base arrow as a single generator.
run :: (Run f arr, Law f arr, Bind f arr) => f arr a b -> arr a b Source #
Fold the free syntax into the same base category.
Defaults to , so the single eliminator vocabulary is
coherent wherever it type-checks. Instances may still override this
with a direct implementation if the weaker constraints of bind idRun do
not already imply Law and Bind.
bind :: forall arr' (arr :: Cat2) a b. (Law f arr', Bind f arr) => (arr :~> arr') -> f arr a b -> arr' a b Source #
The universal fold out of the free construction into any
Law-abiding target category.
Instances
| Layer (Free :: (Type -> Type -> Type) -> Type -> Type -> Type) Source # | Layer instance for the free category. Without object constraints, folding is just recursive application of the target category's composition. | ||||||||||||
Defined in Circuit.Layer Associated Types
Methods unit :: forall (arr :: Type -> Type -> Type). Category arr => arr :~> Free arr Source # run :: (Run (Free :: (Type -> Type -> Type) -> Type -> Type -> Type) arr, Law (Free :: (Type -> Type -> Type) -> Type -> Type -> Type) arr, Bind (Free :: (Type -> Type -> Type) -> Type -> Type -> Type) arr) => Free arr a b -> arr a b Source # bind :: forall arr' (arr :: Cat2) a b. (Law (Free :: (Type -> Type -> Type) -> Type -> Type -> Type) arr', Bind (Free :: (Type -> Type -> Type) -> Type -> Type -> Type) arr) => (arr :~> arr') -> Free arr a b -> arr' a b Source # | |||||||||||||
| Layer (Syntax ((SigCompose :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPar w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigSwap w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigCopy w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigDiscard w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPlus w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: (SigZero w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type)))))))) Source # | Free symmetric monoidal category with a bimonoid. Structural rows are interpreted in the target category: parallel
composition uses
| ||||||||||||
Defined in Circuit.Net Methods unit :: forall (arr :: Type -> Type -> Type). Category arr => arr :~> Syntax ((SigCompose :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPar w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigSwap w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigCopy w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigDiscard w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPlus w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: (SigZero w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type))))))) arr Source # run :: (Run (Syntax ((SigCompose :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPar w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigSwap w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigCopy w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigDiscard w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPlus w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: (SigZero w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type)))))))) arr, Law (Syntax ((SigCompose :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPar w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigSwap w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigCopy w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigDiscard w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPlus w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: (SigZero w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type)))))))) arr, Bind (Syntax ((SigCompose :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPar w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigSwap w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigCopy w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigDiscard w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPlus w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: (SigZero w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type)))))))) arr) => Syntax ((SigCompose :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPar w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigSwap w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigCopy w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigDiscard w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPlus w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: (SigZero w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type))))))) arr a b -> arr a b Source # bind :: forall arr' (arr :: Cat2) a b. (Law (Syntax ((SigCompose :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPar w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigSwap w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigCopy w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigDiscard w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPlus w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: (SigZero w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type)))))))) arr', Bind (Syntax ((SigCompose :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPar w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigSwap w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigCopy w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigDiscard w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPlus w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: (SigZero w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type)))))))) arr) => (arr :~> arr') -> Syntax ((SigCompose :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPar w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigSwap w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigCopy w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigDiscard w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPlus w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: (SigZero w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type))))))) arr a b -> arr' a b Source # | |||||||||||||
type (:~>) (arr :: k -> k1 -> Type) (arr' :: k -> k1 -> Type) = forall (x :: k) (y :: k1). arr x y -> arr' x y Source #
An arrow-to-arrow mapping (a natural transformation between profunctors).
lower :: forall (f :: Cat2 -> Cat2) (arr :: Type -> Type -> Type) (arr' :: Type -> Type -> Type). (Layer f, Category arr) => (f arr :~> arr') -> arr :~> arr' Source #
The left direction of the hom-set isomorphism: restrict a map out of the free layer to the generators.
Operators
(.>) :: forall {k} arr (a :: k) (b :: k) (c :: k). Category arr => arr a b -> arr b c -> arr a c Source #
Forward composition. f .> g = g . f
Bimonoid (structural rules)
class Copy (arr :: Type -> Type -> Type) a where Source #
Copy a value into a pair.
Laws:
fst . copy = id -- left unit snd . copy = id -- right unit (copy × id) . copy = (id × copy) . copy -- coassociativity braid . copy = copy -- cocommutativity
Instances
| Copy FinRel () Source # | |
Defined in Circuit.FinRel | |
| Copy (->) a => Copy Process a Source # | |
Defined in Circuit.Process | |
| Copy Pullback a Source # | Pullback-instance of the comonoid structure. Copy's pullback is addition; discard's pullback is the zero
cotangent. These are not used by the transposition step of reverse-mode
AD (which encodes structural rows as
NOTE: neither method here uses an |
Defined in Circuit.Pullback | |
| KnownNat n => Copy FinRel (FinObj n) Source # | |
| (Copy arr a, Merge arr a) => Copy (Dagger arr) a Source # | Forward copy, backward add — the bimonoid self-duality. The interlock is the point to notice: |
Defined in Circuit.Dagger | |
| Copy (->) Integer Source # | |
| Copy (->) () Source # | Unit trivially copies and discards.
|
Defined in Circuit.Bimonoid | |
| Copy (->) Bool Source # | Booleans copy and discard.
|
| Copy (->) Double Source # | |
| Copy (->) Float Source # | |
| Copy (->) Int Source # | Numeric scalars copy and discard pointwise.
|
| Copy (->) (Maybe a) Source # | Maybe copies and discards as a whole value. |
| Copy (->) [a] Source # | Lists copy and discard as a whole value. |
Defined in Circuit.Bimonoid | |
| Copy (->) (a, b) Source # | Products copy and discard as a whole value. |
Defined in Circuit.Bimonoid | |
class Discard (arr :: k -> Type -> Type) (a :: k) where Source #
Discard a value.
Instances
| Discard FinRel () Source # | |
Defined in Circuit.FinRel | |
| Discard Process (a :: Type) Source # | |
Defined in Circuit.Process | |
| Discard Pullback (a :: Type) Source # | |
Defined in Circuit.Pullback | |
| KnownNat n => Discard FinRel (FinObj n :: Type) Source # | |
| (Discard arr a, Zero arr a) => Discard (Dagger arr :: Type -> Type -> Type) (a :: Type) Source # | |
Defined in Circuit.Dagger | |
| Discard (->) Integer Source # | |
Defined in Circuit.Bimonoid | |
| Discard (->) () Source # | |
Defined in Circuit.Bimonoid | |
| Discard (->) Bool Source # | |
Defined in Circuit.Bimonoid | |
| Discard (->) Double Source # | |
Defined in Circuit.Bimonoid | |
| Discard (->) Float Source # | |
Defined in Circuit.Bimonoid | |
| Discard (->) Int Source # | |
Defined in Circuit.Bimonoid | |
| Discard (->) (Maybe a :: Type) Source # | |
Defined in Circuit.Bimonoid | |
| Discard (->) ([a] :: Type) Source # | |
Defined in Circuit.Bimonoid | |
| Discard (->) ((a, b) :: Type) Source # | |
Defined in Circuit.Bimonoid | |
class Merge (arr :: Type -> Type -> Type) a where Source #
Combine two values of the channel type.
Not the same as arithmetic +; this is the monoid operation by which
parallel contributions to the same wire combine.
Instances
| Merge FinRel () Source # | |
Defined in Circuit.FinRel | |
| Merge (->) a => Merge Process a Source # | |
Defined in Circuit.Process | |
| Merge (->) a => Merge Pullback a Source # | Pullback-instance of the additive/monoid structure. Addition's pullback is copying; zero's pullback is discarding.
|
Defined in Circuit.Pullback | |
| KnownNat n => Merge FinRel (FinObj n) Source # | |
| (Merge arr a, Copy arr a) => Merge (Dagger arr) a Source # | Forward add, backward copy. |
Defined in Circuit.Dagger | |
| Merge (->) Integer Source # | |
| Merge (->) () Source # | The unit type carries the trivial monoid.
|
Defined in Circuit.Bimonoid | |
| Merge (->) Bool Source # | Boolean monoid under disjunction. Idempotent because
|
| Merge (->) Double Source # | |
| Merge (->) Float Source # | |
| Merge (->) Int Source # | Numeric carriers.
|
| (Merge (->) a, Zero (->) a) => Merge (->) [a] Source # | Lists via elementwise For lists of unequal length, the shorter list is implicitly extended
with the element
|
Defined in Circuit.Bimonoid | |
| (Merge (->) a, Merge (->) b) => Merge (->) (a, b) Source # | Componentwise
|
Defined in Circuit.Bimonoid | |
class Zero (arr :: Type -> k -> Type) (a :: k) where Source #
The neutral element for plus.
Instances
| Zero FinRel () Source # | |
Defined in Circuit.FinRel | |
| Zero (->) a => Zero Process (a :: Type) Source # | |
Defined in Circuit.Process | |
| Zero (->) a => Zero Pullback (a :: Type) Source # | |
Defined in Circuit.Pullback | |
| KnownNat n => Zero FinRel (FinObj n :: Type) Source # | |
| (Zero arr a, Discard arr a) => Zero (Dagger arr :: Type -> Type -> Type) (a :: Type) Source # | |
Defined in Circuit.Dagger | |
| Zero (->) Integer Source # | |
Defined in Circuit.Bimonoid | |
| Zero (->) () Source # | |
Defined in Circuit.Bimonoid | |
| Zero (->) Bool Source # | |
Defined in Circuit.Bimonoid | |
| Zero (->) Double Source # | |
Defined in Circuit.Bimonoid | |
| Zero (->) Float Source # | |
Defined in Circuit.Bimonoid | |
| Zero (->) Int Source # | |
Defined in Circuit.Bimonoid | |
| Zero (->) ([a] :: Type) Source # | |
Defined in Circuit.Bimonoid | |
| (Zero (->) a, Zero (->) b) => Zero (->) ((a, b) :: Type) Source # | |
Defined in Circuit.Bimonoid | |
type CopyDiscard (arr :: Type -> Type -> Type) a = (Copy arr a, Discard arr a) Source #
The bundled comonoid class, retained as a synonym.
type MergeZero (arr :: Type -> Type -> Type) a = (Merge arr a, Zero arr a) Source #
The bundled monoid class, retained as a synonym.
type Bimonoid (arr :: Type -> Type -> Type) a = (Copy arr a, Discard arr a, Merge arr a, Zero arr a) Source #
Both the comonoid and monoid on a channel object.
A constraint synonym — no instance required. On a cartesian base arrow,
every type carries both structures. This is the precondition for
mirror to be total on that base arrow.
Dagger (free dagger category)
data Dagger (arr :: k -> k -> Type) (a :: k) (b :: k) Source #
The free dagger category over a base arrow.
Dagger arr a b is a pair of arrows arr a b (forward) and
arr b a (backward). Composition is covariant forward, contravariant
backward: Dagger f g . Dagger f' g' = Dagger (f . f') (g' . g).
>>>let d = Dagger (+1) (subtract 1) :: Dagger (->) Int Int>>>front d 56>>>back d 65
Constructors
| Dagger | |
Instances
| Channel t arr => Channel (t :: k -> k -> k) (Dagger arr :: k -> k -> Type) Source # | |
Defined in Circuit.Dagger | |
| Strength t arr => Strength (t :: k -> k -> k) (Dagger arr :: k -> k -> Type) Source # | |
| Traced t arr => Traced (t :: k -> k -> k) (Dagger arr :: k -> k -> Type) Source # | |
| Action t arr => Action (t :: k -> k -> k) (Dagger arr :: k -> k -> Type) Source # | |
Defined in Circuit.Dagger | |
| Tensor t arr => Tensor (t :: k -> k -> k) (Dagger arr :: k -> k -> Type) Source # | |
| Unital t arr => Unital (t :: k -> k -> k) (Dagger arr :: k -> k -> Type) Source # | |
| (CopyT t arr a, MergeT t arr a) => CopyT (t :: k -> k -> k) (Dagger arr :: k -> k -> Type) (a :: k) Source # | Tensor-generic bimonoid interlock through These instances mirror the cartesian ones above, but work for any wiring
tensor
|
Defined in Circuit.Dagger | |
| (DiscardT t arr a, ZeroT t arr a) => DiscardT (t :: k -> k -> k) (Dagger arr :: k -> k -> Type) (a :: k) Source # | |
| (MergeT t arr a, CopyT t arr a) => MergeT (t :: k -> k -> k) (Dagger arr :: k -> k -> Type) (a :: k) Source # | |
Defined in Circuit.Dagger | |
| (ZeroT t arr a, DiscardT t arr a) => ZeroT (t :: k -> k -> k) (Dagger arr :: k -> k -> Type) (a :: k) Source # | |
| Category arr => Category (Dagger arr :: k -> k -> Type) Source # | |
| (Discard arr a, Zero arr a) => Discard (Dagger arr :: Type -> Type -> Type) (a :: Type) Source # | |
Defined in Circuit.Dagger | |
| (Zero arr a, Discard arr a) => Zero (Dagger arr :: Type -> Type -> Type) (a :: Type) Source # | |
Defined in Circuit.Dagger | |
| (Copy arr a, Merge arr a) => Copy (Dagger arr) a Source # | Forward copy, backward add — the bimonoid self-duality. The interlock is the point to notice: |
Defined in Circuit.Dagger | |
| (Merge arr a, Copy arr a) => Merge (Dagger arr) a Source # | Forward add, backward copy. |
Defined in Circuit.Dagger | |
transpose :: forall {k} (arr :: k -> k -> Type) (a :: k) (b :: k). Dagger arr a b -> Dagger arr b a Source #
The dagger operation: braid forward and backward.
Involutive: transpose . transpose = id.
SMC
type SMC (w :: Type -> Type -> Type) (arr :: Type -> Type -> Type) = Syntax ((SigCompose :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPar w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: (SigSwap w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type))) arr Source #
Free symmetric monoidal category over wiring tensor w.
Net
type Net (w :: Type -> Type -> Type) (arr :: Type -> Type -> Type) = Syntax ((SigCompose :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPar w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigSwap w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigCopy w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigDiscard w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigPlus w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: (SigZero w :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type))))))) arr Source #
The free symmetric monoidal category with a bimonoid.
Net is the free Syntax over the signature sum
SigCompose:+:SigParw:+:SigSwapw:+:SigCopyw:+:SigDiscardw:+:SigPlusw:+:SigZerow
The Lift constructor embeds a base arrow; the Op constructor holds
one of the signature nodes. Smart constructors lift and braid
build the common cases, and widen embeds an entire SMC circuit.
melt :: forall (w :: Type -> Type -> Type) (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) a b. (Traced t arr, Action w arr) => Net w arr a b -> Trace t arr a b Source #
Melt the structural rows of a Net into the free Trace syntax.
The interpretation from the free symmetric monoidal category with
bimonoid to the free traced monoidal category. Structural rows (SigPar,
SigCopy, SigPlus, etc.) become opaque base-arrow operations wrapped in
base; SigCompose uses the Category instance of Trace.
>>>eval (melt (lift (+1) :: Net (,) (->) Int Int) :: Trace (,) (->) Int Int) 56
Pullback (linear cotangent maps)
A linear map from output cotangents to input cotangents, read as
an arrow b -> a.
>>>let pb = Pullback (*2) :: Pullback Double Double>>>runPullback pb 36.0
Constructors
| Pullback | |
Fields
| |
Instances
| Copy Pullback a Source # | Pullback-instance of the comonoid structure. Copy's pullback is addition; discard's pullback is the zero
cotangent. These are not used by the transposition step of reverse-mode
AD (which encodes structural rows as
NOTE: neither method here uses an |
Defined in Circuit.Pullback | |
| Merge (->) a => Merge Pullback a Source # | Pullback-instance of the additive/monoid structure. Addition's pullback is copying; zero's pullback is discarding.
|
Defined in Circuit.Pullback | |
| Category Pullback Source # | |
| Discard Pullback (a :: Type) Source # | |
Defined in Circuit.Pullback | |
| Zero (->) a => Zero Pullback (a :: Type) Source # | |
Defined in Circuit.Pullback | |
| Channel (,) Pullback Source # | Cartesian channel plumbing for pullbacks. |
| Strength (,) Pullback Source # | |
| Traced (,) Pullback Source # | The cartesian trace for pullbacks. The body is a linear map (dx, db) = f (dx, dc) solved by the same lazy knot that a differentiable arrow uses. For
strict carriers with nonzero channel self-coupling this diverges,
exactly as the lazy differentiable trace does. Unlike the differentiable
case, though, the equation here is always affine —
|
| Action (,) Pullback Source # | |
Defined in Circuit.Pullback | |
| Tensor (,) Pullback Source # | |
| Unital (,) Pullback Source # | Parallel composition pairs pullbacks independently;
|
evalPullback :: Net (,) Pullback b a -> b -> a Source #
Evaluate a pullback net at a single output cotangent.
This is the one-shot reverse pass: the net was built by transposing a
smooth net, and applying it to a cotangent db yields the input
cotangent da.
Hyper
newtype HyperA (arr :: Type -> k -> Type) (a :: k) (b :: k) Source #
A hyperfunction from a to b over the base category arr.
Constructors
| HyperA | |
Instances
| Category Hyper Source # | |
| Channel (,) Hyper Source # | |
| Strength (,) Hyper Source # | |
| Traced (,) Hyper Source # | |
| Monad m => Channel (,) (HyperA (K m) :: Type -> Type -> Type) Source # | |
| Monad m => Strength (,) (HyperA (K m) :: Type -> Type -> Type) Source # | |
| MonadFix m => Traced (,) (HyperA (K m) :: Type -> Type -> Type) Source # | |
| Monad m => Category (HyperA (K m) :: Type -> Type -> Type) Source # | |
lift :: (a -> b) -> Hyper a b Source #
Embed a plain function into a hyperfunction.
>>>observe (lift (+1)) 56
observe :: Hyper a b -> a -> b Source #
Extract a plain function from a hyperfunction.
>>>observe (lift reverse) "hello""olleh"
push :: (a -> b) -> Hyper a b -> Hyper a b Source #
Push a plain function onto a hyperfunction.
>>>observe (push (+1) (lift (*2))) 56
runHyper :: Hyper a a -> a Source #
Close the self-referential loop.
>>>runHyper (Hyper $ \_ -> 42 :: Int)42
liftK :: forall (m :: Type -> Type) a b. Monad m => K m a b -> HyperA (K m) a b Source #
Embed a Kleisli arrow into a hyperfunction.
observeK :: Monad m => HyperA (K m) a b -> a -> m b Source #
Extract the underlying Kleisli arrow from a hyperfunction.
pushK :: forall (m :: Type -> Type) a b. Monad m => K m a b -> HyperA (K m) a b -> HyperA (K m) a b Source #
Push a Kleisli arrow onto a hyperfunction.
runHyperK :: MonadFix m => HyperA (K m) a a -> m a Source #
Close the self-referential loop using mfix.
encode :: Trace (,) (->) a b -> Hyper a b Source #
Encode a function-category Trace into a Hyper.
This is the unique traced functor from the initial syntax (Trace)
to the final object (Hyper), satisfying the commuting triangle
.observe . encode = eval
base constructors embed directly via lift; yank
constructors become trace over a hyperfunction.
>>>import qualified Circuit.Trace as Trace>>>observe (encode (Trace.base (+1) :: Trace.Trace (,) (->) Int Int)) 56
encodeK :: forall (m :: Type -> Type) a b. MonadFix m => Trace (,) (K m) a b -> HyperA (K m) a b Source #
encodeEither :: (Either a b -> Either a c) -> Hyper (Either a b -> c) (Either a b -> c) Source #
Encode an Either-loop as a self-referential Hyper.
Whereas encode handles the (,) tensor using Hyper's own Traced
instance, this preserves the Either-loop state in the function domain.
Left a feeds back; Right c terminates with output.
>>>:{let step = \case Right n | n < 3 -> Left (n + 1) Right n -> Right n Left n | n < 3 -> Left (n + 1) Left n -> Right n :}
>>>runEither step (0 :: Int)3
runEither :: (Either a b -> Either a c) -> b -> c Source #
Run an encodeEither-encoded circuit from initial input b.
encodeEither embeds the Either state machine into Hyper, runHyper
ties the self-referential knot, and Right b injects the initial state.
>>>:{let step = \case Right n | n < 3 -> Left (n + 1) Right n -> Right n Left n | n < 3 -> Left (n + 1) Left n -> Right n :}
>>>runEither step (0 :: Int)3
Tensor
superpose :: forall t (arr :: Type -> Type -> Type) a b c d. (Tensor t arr, Traced t arr) => Trace t arr a b -> Trace t arr c d -> Trace t arr (t a c) (t b d) Source #
Fused parallel composition for Trace when the feedback tensor matches.
Two yanks in parallel superpose into one yank over a paired channel,
satisfying the superposing axiom of traced monoidal categories:
superpose (trace f) (trace g) = trace (pre . tensor f g . post)
where pre and post rearrange the paired channel via associators
and braiding. This preserves sharing for recursive circuits; the lawful
Tensor instance falls back to independent evaluation.
>>>let k1 = yank (base (\(ns, _) -> (1 : ns, take 3 ns))) :: Trace (,) (->) [Int] [Int]>>>let k2 = yank (base (\(ns, _) -> (2 : ns, take 3 ns)))>>>eval (superpose k1 k2) ([], [])([1,1,1],[2,2,2])
The same fusion works for K, preserving sharing across the
recursive channels under MonadFix.
>>>let k1 = yank (base (K $ \(ns, _) -> pure (1 : ns, take 3 ns))) :: Trace (,) (K Identity) [Int] [Int]>>>let k2 = yank (base (K $ \(ns, _) -> pure (2 : ns, take 3 ns)))>>>runK (eval (superpose k1 k2)) ([], [])Identity ([1,1,1],[2,2,2])
Stamped values
A value a labelled by an occurrence token r.
Constructors
| Stamped | |
Instances
| Bifunctor Stamped Source # | |
| Functor (Stamped r) Source # | |
| Foldable (Stamped r) Source # | |
Defined in Circuit.Stamped Methods fold :: Monoid m => Stamped r m -> m # foldMap :: Monoid m => (a -> m) -> Stamped r a -> m # foldMap' :: Monoid m => (a -> m) -> Stamped r a -> m # foldr :: (a -> b -> b) -> b -> Stamped r a -> b # foldr' :: (a -> b -> b) -> b -> Stamped r a -> b # foldl :: (b -> a -> b) -> b -> Stamped r a -> b # foldl' :: (b -> a -> b) -> b -> Stamped r a -> b # foldr1 :: (a -> a -> a) -> Stamped r a -> a # foldl1 :: (a -> a -> a) -> Stamped r a -> a # toList :: Stamped r a -> [a] # length :: Stamped r a -> Int # elem :: Eq a => a -> Stamped r a -> Bool # maximum :: Ord a => Stamped r a -> a # minimum :: Ord a => Stamped r a -> a # | |
| Traversable (Stamped r) Source # | |
| (Eq r, Eq a) => Eq (Stamped r a) Source # | |
| (Show r, Show a) => Show (Stamped r a) Source # | |
Additive poles
Bias for ordered choice in scheduling and additive disjunction.
LeftFirst and RightFirst are used by shared-medium fusion in
Circuit.Shared and by additive disjunction in Circuit.Poles.
Constructors
| LeftFirst | |
| RightFirst |
Par (multiplicative disjunction)
class Category arr => Par (p :: k -> k -> k) (arr :: k -> k -> Type) where Source #
Multiplicative disjunction action on a category.
parP is the tensor product of morphisms. The unitors witness that
⊥ ⅋ a ≅ a and a ⅋ ⊥ ≅ a.
Methods
parP :: forall (a :: k) (b :: k) (c :: k) (d :: k). arr a b -> arr c d -> arr (p a c) (p b d) Source #
Parallel composition under tensor.
unitlP :: forall (a :: k). arr (p (Bot p) a) a Source #
Left unitor: ⊥ ⅋ a -> a.
unitlP' :: forall (a :: k). arr a (p (Bot p) a) Source #
Inverse left unitor: a -> ⊥ ⅋ a.
unitrP :: forall (a :: k). arr (p a (Bot p)) a Source #
Right unitor: a ⅋ ⊥ -> a.
unitrP' :: forall (a :: k). arr a (p a (Bot p)) Source #
Inverse right unitor: a -> a ⅋ ⊥.
Instances
| Monad m => Par Either (K m :: Type -> Type -> Type) Source # | Coproduct as multiplicative disjunction on |
| Par Either (->) Source # | Coproduct as multiplicative disjunction on functions. The unit is the initial object |
distL :: (a, Either b c) -> Either (a, b) c Source #
Left linear distributor: A ⊗ (B ⅋ C) -> (A ⊗ B) ⅋ C.
For (,) and Either this is the one-way product-over-coproduct map.
Note that (_, Right c) = Right c discards the a; this is legal
affinely but not in strict MLL. The distributors already live in the
affine fragment.
distR :: (Either b c, a) -> Either b (c, a) Source #
Right linear distributor: (B ⅋ C) ⊗ A -> B ⅋ (C ⊗ A).
Mirror of distL: the same affine discard is present when the left
summand is taken.
Mix: the canonical map ⊥ -> 1 from tensor unit to tensor unit.
Every ⊥-value is vacuous, so it maps to the unique tensor unit.
Linear implication (internal hom)
class Category arr => Lolli (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) where Source #
Closed monoidal structure: A ⊸ B is the right adjoint of tensor.
Maps A ⊗ B -> C correspond to maps A -> B ⊸ C via curry/uncurry.
eval is the counit A ⊗ (A ⊸ B) -> B (hom on the right of the tensor).
That is the existing Chu convention; it differs from uncurry id by a
braid. lolli is identity on the implication object, used to mention
it.
Kind is fixed to Type so type applications stay concrete (GHC 9.14
panics on kind-polymorphic TypeApplications here).
Associated Types
type LolliT (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) a b Source #
The implication object A ⊸ B.
Indexed by the base arrow as well as the tensor, so (->) and
Mat can both close (,) without colliding.
Methods
lolli :: arr a b -> arr (LolliT t arr a b) (LolliT t arr a b) Source #
Identity at the implication object. The argument is a type proxy.
eval :: arr (t a (LolliT t arr a b)) b Source #
Evaluation counit A ⊗ (A ⊸ B) -> B.
curry :: arr (t a b) c -> arr a (LolliT t arr b c) Source #
Curry the left factor: (A ⊗ B -> C) -> (A -> B ⊸ C).
uncurry :: arr a (LolliT t arr b c) -> arr (t a b) c Source #
Uncurry the left factor: (A -> B ⊸ C) -> (A ⊗ B -> C).
Instances
| Lolli (,) (->) Source # | Cartesian closed structure on functions: implication collapses to function space. | ||||
Defined in Circuit.Linear Associated Types
| |||||
Exponentials
class Tensor t arr => Exponential (t :: k -> k -> k) (arr :: k -> k -> Type) Source #
Exponential modality: object-level types for !A and ?A.
The structural rules are split into independent subclasses so that
affine and linear uses of the modality differ only in their constraint
sets, mirroring the Copy/Discard split at the base-arrow level.
!Ahas a contraction half (BangCopy) and a weakening half (BangWeaken). Linear logic requires both; affine logic requires only weakening.?Acurrently exposes only its unit rule (WhyNotIntro); the ⅋-monoid multiplication on?A(WhyNotMerge) is missing. In the vocabulary ofDagger,?Ais currentlyCoAffine-only (the unitZero) and the missing half isCoRelevant(the mergeMerge).
Associated Types
type Bang (t :: k -> k -> k) (arr :: k -> k -> Type) a Source #
type WhyNot (t :: k -> k -> k) (arr :: k -> k -> Type) a = (result :: Type) | result -> a Source #
Instances
| Exponential (,) (->) Source # | Cartesian collapse: | ||||||||
Defined in Circuit.Linear Associated Types
| |||||||||
class Exponential t arr => BangCopy (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) where Source #
Contraction half of !A: copy !A → !A ⊗ !A.
class Exponential t arr => BangWeaken (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) where Source #
Weakening half of !A: dereliction !A → A and discard !A → I.
class Exponential t arr => WhyNotIntro (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) where Source #
Unit rule for ?A: introduction A → ?A.
Instances
| WhyNotIntro (,) (->) Source # | |
class (Exponential t arr, Par p arr) => WhyNotMonoid (t :: Type -> Type -> Type) (p :: Type -> Type -> Type) (arr :: Type -> Type -> Type) where Source #
The ⅋-monoid structure on ?A.
Dual to the !-comonoid (BangCopy / BangWeaken), but living on the
tensor product rather than the tensor product. mergeE is the
multiplication ?A ⅋ ?A → ?A and zeroE is the unit ⊥ → ?A.
type LinearBang (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) = (Exponential t arr, BangCopy t arr, BangWeaken t arr) Source #
Linear !A: both contraction and weakening.
type AffineBang (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) = (Exponential t arr, BangWeaken t arr) Source #
Affine !A: weakening only.
Channel product
class Unital t arr => Tensor (t :: k -> k -> k) (arr :: k -> k -> Type) where Source #
The tensor action of t on a category arr, without braiding.
tensor is the tensor product of morphisms (parallel composition on
disjoint wires). The unitors live in the Unital superclass.
Kind-polymorphic: t and arr share object kind (inferred via PolyKinds).
Methods
tensor :: forall (a :: k) (b :: k) (c :: k) (d :: k). arr a b -> arr c d -> arr (t a c) (t b d) Source #
Parallel composition: run two arrows on disjoint wires.
>>>tensor ((+1) :: Int -> Int) ((*2) :: Int -> Int) (3, 4)(4,8)
Instances
| Tensor (,) Process Source # | |
| Tensor (,) Pullback Source # | |
| Monad m => Tensor Either (K m :: Type -> Type -> Type) Source # | Coproduct tensor action on
|
| Tensor Either (->) Source # | Coproduct tensor action on functions.
|
| Monad m => Tensor These (K m :: Type -> Type -> Type) Source # | Inclusive tensor action on |
| Tensor These (->) Source # | Inclusive tensor action on functions. |
| Monad m => Tensor (,) (K m :: Type -> Type -> Type) Source # | Cartesian tensor on |
| Tensor (,) (->) Source # | Cartesian tensor action on functions. |
Defined in Circuit.Tensor | |
| (Tensor t arr, Traced t' arr) => Tensor (t :: Type -> Type -> Type) (Trace t' arr :: Type -> Type -> Type) Source # | Lift This is the single lawful instance: it evaluates each |
| Tensor w arr => Tensor (w :: Type -> Type -> Type) (SMC w arr :: Type -> Type -> Type) Source # | |
| Tensor t arr => Tensor (t :: k -> k -> k) (Dagger arr :: k -> k -> Type) Source # | |
class Tensor t arr => Action (t :: k -> k -> k) (arr :: k -> k -> Type) where Source #
The action of a tensor t on a category arr, extended with a
symmetric braiding.
This is the self-action of a symmetric monoidal category: t acts on
arr by taking morphisms to morphisms over paired objects, and braid
provides the symmetry.
Methods
braid :: forall (a :: k) (b :: k). arr (t a b) (t b a) Source #
Symmetric braiding.
>>>braid (3, 4) :: (Int, Int)(4,3)
Instances
| Action (,) Process Source # | |
Defined in Circuit.Process | |
| Action (,) Pullback Source # | |
Defined in Circuit.Pullback | |
| Monad m => Action Either (K m :: Type -> Type -> Type) Source # | Coproduct symmetry on |
| Action Either (->) Source # | Coproduct symmetry on functions.
|
| Monad m => Action These (K m :: Type -> Type -> Type) Source # | Inclusive symmetry on |
| Action These (->) Source # | Inclusive symmetry on functions. |
| Monad m => Action (,) (K m :: Type -> Type -> Type) Source # | |
Defined in Circuit.Tensor | |
| Action (,) (->) Source # | Cartesian symmetry on functions. |
Defined in Circuit.Tensor | |
| (Action t arr, Traced t' arr) => Action (t :: Type -> Type -> Type) (Trace t' arr :: Type -> Type -> Type) Source # | |
Defined in Circuit.Tensor | |
| Action w arr => Action (w :: Type -> Type -> Type) (SMC w arr :: Type -> Type -> Type) Source # | |
Defined in Circuit.SMC | |
| Action t arr => Action (t :: k -> k -> k) (Dagger arr :: k -> k -> Type) Source # | |
Defined in Circuit.Dagger | |
Shared-medium fusion (the ⅋ connective)
A schedule decision: which poles advance on a shared channel.
A schedule drives shared-medium fusion.
The state s is threaded through the fusion; in typical use it is the
shared channel. At each step the schedule looks at the state and chooses
which poles advance, returning the updated schedule state.
class Tensor t arr => Shared (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) where Source #
Tensors that support shared-medium fusion of two knot bodies.
This is the operational content of the multiplicative disjunction: two
sub-loops share one channel, and a Schedule resolves the interleaving.
Contrast superpose, which keeps the channels independent (⊗).
Methods
sharedBy :: Schedule s -> arr (t s a) (t s b) -> arr (t s c) (t s d) -> arr (t s (t a c)) (t s (These b d)) Source #
Fuse two knot bodies over a shared channel.
The combined body has type arr (t s (t a c)) (t s (These b d)): one
shared state s, paired inputs a and c, and a partial output. At
each step the schedule chooses which body advances; the gated body's
input is discarded and no output is produced for that side.