| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Circuit.Layer
Description
The free-layer / free-forgetful adjunction tower.
Each layer f is a free construction over a base arrow:
runFree— free categoryrunSMC— free symmetric monoidal categoryrunTrace— free traced monoidal category (in Circuit.Trace)runNet— free symmetric monoidal category with bimonoid
Law says what the target category must satisfy to receive a bind
fold; Run says what the base category must satisfy for a same-category
run; and Bind captures any extra source constraints needed when the
free syntax has structural rows.
The hom-set isomorphism is stated once, generically:
bind h . unit = h (β) bind unit = id (η) run = bind id (coherence, where both sides are defined)
Composition of layers is just nesting — no new operator, no bespoke coherence lemmas.
Synopsis
- 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
- 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
- data Free (arr :: k -> k -> Type) (a :: k) (b :: k) where
- freeze :: forall {k} arr (a :: k) (b :: k). Category arr => Free arr a b -> arr a b
- lower :: forall (f :: Cat2 -> Cat2) (arr :: Type -> Type -> Type) (arr' :: Type -> Type -> Type). (Layer f, Category arr) => (f arr :~> arr') -> arr :~> arr'
Free-layer class
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).
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 # | |||||||||||||
Free category
data Free (arr :: k -> k -> Type) (a :: k) (b :: k) where 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
Constructors
| Lift :: forall {k} (arr :: k -> k -> Type) (a :: k) (b :: k). arr a b -> Free arr a b | Embed a base arrow. |
| Compose :: forall {k} (arr :: k -> k -> Type) (b1 :: k) (b :: k) (a :: k). Free arr b1 b -> Free arr a b1 -> Free arr a b | Sequential composition. |
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 # | |||||||||||||