circuits
Safe HaskellNone
LanguageGHC2024

Circuit.Category

Description

Local category hierarchy without object constraints.

Category is local so morphisms can carry an associated object constraint. This version removes the constraint-family apparatus: objects are unconstrained at the type level and legitimacy is an audit concern rather than a discharge concern.

Operator convention

The tip of the operator points in the direction of data flow.

  • | means apply to a value: (|>) feeds a value into a function (forward application, like &), and (<|) applies a function to a value (backward application, like $).
  • . means compose morphisms: (.>) is forward composition and (.) is backward composition as usual.
Synopsis

Documentation

class Category (arr :: k -> k -> Type) where Source #

A category without object constraints.

Ob arr a is gone; every object is mentionable. Lawfulness is checked by the axioma oracles rather than by type-level discharge.

Methods

id :: forall (a :: k). arr a a Source #

Identity morphism.

(.) :: forall (b :: k) (c :: k) (a :: k). arr b c -> arr a b -> arr a c Source #

Composition (right-to-left).

Instances

Instances details
Category Morphism Source # 
Instance details

Defined in Circuit.Poly

Methods

id :: forall (a :: Poly). Morphism a a Source #

(.) :: forall (b :: Poly) (c :: Poly) (a :: Poly). Morphism b c -> Morphism a b -> Morphism a c Source #

Category Hyper Source # 
Instance details

Defined in Circuit.Hyper

Methods

id :: Hyper a a Source #

(.) :: Hyper b c -> Hyper a b -> Hyper a c Source #

Category Process Source # 
Instance details

Defined in Circuit.Process

Methods

id :: Process a a Source #

(.) :: Process b c -> Process a b -> Process a c Source #

Category Pullback Source # 
Instance details

Defined in Circuit.Pullback

Methods

id :: Pullback a a Source #

(.) :: Pullback b c -> Pullback a b -> Pullback a c Source #

Category arr => Category (AlgCat arr :: Type -> Type -> Type) Source # 
Instance details

Defined in Circuit.Syntax

Methods

id :: AlgCat arr a a Source #

(.) :: AlgCat arr b c -> AlgCat arr a b -> AlgCat arr a c Source #

Monad m => Category (K m :: Type -> Type -> Type) Source # 
Instance details

Defined in Circuit.Category

Methods

id :: K m a a Source #

(.) :: K m b c -> K m a b -> K m a c Source #

Monad m => Category (HyperA (K m) :: Type -> Type -> Type) Source # 
Instance details

Defined in Circuit.Hyper

Methods

id :: HyperA (K m) a a Source #

(.) :: HyperA (K m) b c -> HyperA (K m) a b -> HyperA (K m) a c Source #

Category arr => Category (Net w arr :: Type -> Type -> Type) Source #

The Category instance is the generic free-category instance: id is a lifted identity and composition is a SigCompose node.

Instance details

Defined in Circuit.Net

Methods

id :: Net w arr a a Source #

(.) :: Net w arr b c -> Net w arr a b -> Net w arr a c Source #

Category arr => Category (SMC w arr :: Type -> Type -> Type) Source # 
Instance details

Defined in Circuit.SMC

Methods

id :: SMC w arr a a Source #

(.) :: SMC w arr b c -> SMC w arr a b -> SMC w arr a c Source #

Category arr => Category (Trace t arr :: Type -> Type -> Type) Source # 
Instance details

Defined in Circuit.Trace

Methods

id :: Trace t arr a a Source #

(.) :: Trace t arr b c -> Trace t arr a b -> Trace t arr a c Source #

Category (->) Source #

Unconstrained function category.

Instance details

Defined in Circuit.Category

Methods

id :: a -> a Source #

(.) :: (b -> c) -> (a -> b) -> a -> c Source #

Category arr => Category (Dagger arr :: k -> k -> Type) Source # 
Instance details

Defined in Circuit.Dagger

Methods

id :: forall (a :: k). Dagger arr a a Source #

(.) :: forall (b :: k) (c :: k) (a :: k). Dagger arr b c -> Dagger arr a b -> Dagger arr a c Source #

Category arr => Category (Free arr :: k -> k -> Type) Source # 
Instance details

Defined in Circuit.Layer

Methods

id :: forall (a :: k). Free arr a a Source #

(.) :: forall (b :: k) (c :: k) (a :: k). Free arr b c -> Free arr a b -> Free arr a c Source #

(Strength t arr, Pointed (Unit t), TensorSeed t) => Category (SomeBody t arr :: Type -> Type -> Type) Source #

Category instance for SomeBody.

The carrier of the composite is the tensor of the two carriers, and the stored seed is combined with seedPair. Identity needs a seed at the tensor unit, hence the 'Pointed (Unit t)' requirement. Tensors whose unit is uninhabited (e.g. Either with Unit Either = Void) therefore do not admit an identity; tensors without a canonical value-level pairing (also Either, These) do not admit composition.

Instance details

Defined in Circuit.Body

Methods

id :: SomeBody t arr a a Source #

(.) :: SomeBody t arr b c -> SomeBody t arr a b -> SomeBody t arr a c Source #

Strength t arr => Category (Circ t arr :: k -> k -> Type) Source #

Category instance for Circ.

The laws hold only up to invertible Sq: on-the-nose associativity and unitality are impossible as Haskell values because the carriers of the two sides differ. Observational witnesses live in Axioma.Circ.

Instance details

Defined in Circuit.Circ

Methods

id :: forall (a :: k). Circ t arr a a Source #

(.) :: forall (b :: k) (c :: k) (a :: k). Circ t arr b c -> Circ t arr a b -> Circ t arr a c Source #

Category arr => Category (Body t ch arr :: k3 -> k3 -> Type) Source # 
Instance details

Defined in Circuit.Body

Methods

id :: forall (a :: k3). Body t ch arr a a Source #

(.) :: forall (b :: k3) (c :: k3) (a :: k3). Body t ch arr b c -> Body t ch arr a b -> Body t ch arr a c Source #

(.>) :: 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

(|>) :: a -> (a -> b) -> b infixl 1 Source #

Forward application. x |> f = f x

(<|) :: (a -> b) -> a -> b infixr 0 Source #

Backward application. f <| x = f x

newtype K (m :: k -> Type) a (b :: k) Source #

Kleisli arrows of a monad, named locally.

Constructors

K 

Fields

Instances

Instances details
Monad m => Distributive (,) Either (K m :: Type -> Type -> Type) Source #

Distributivity of (,) over Either on K m.

Instance details

Defined in Circuit.Tensor

Methods

distl :: K m (a, Either b c) (Either (a, b) (a, c)) Source #

distl' :: K m (Either (a, b) (a, c)) (a, Either b c) Source #

distr :: K m (Either a b, c) (Either (a, c) (b, c)) Source #

distr' :: K m (Either (a, c) (b, c)) (Either a b, c) Source #

annih :: K m (a, Unit Either) (Unit Either) Source #

annih' :: K m (Unit Either) (a, Unit Either) Source #

Monad m => Channel Either (K m :: Type -> Type -> Type) Source #

Cocartesian monoidal structure for K m with Either.

Instance details

Defined in Circuit.Channel

Methods

assoc :: K m (Either (Either a b) c) (Either a (Either b c)) Source #

assoc' :: K m (Either a (Either b c)) (Either (Either a b) c) Source #

slide :: K m (Either a (Either b c)) (Either b (Either a c)) Source #

Monad m => Channel These (K m :: Type -> Type -> Type) Source #

Inclusive monoidal structure for K m with These.

Instance details

Defined in Circuit.Channel

Methods

assoc :: K m (These (These a b) c) (These a (These b c)) Source #

assoc' :: K m (These a (These b c)) (These (These a b) c) Source #

slide :: K m (These a (These b c)) (These b (These a c)) Source #

Monad m => Channel (,) (K m :: Type -> Type -> Type) Source #

Cartesian monoidal structure for K m with (,).

Instance details

Defined in Circuit.Channel

Methods

assoc :: K m ((a, b), c) (a, (b, c)) Source #

assoc' :: K m (a, (b, c)) ((a, b), c) Source #

slide :: K m (a, (b, c)) (b, (a, c)) Source #

Monad m => Channel (,) (HyperA (K m) :: Type -> Type -> Type) Source # 
Instance details

Defined in Circuit.Hyper

Methods

assoc :: HyperA (K m) ((a, b), c) (a, (b, c)) Source #

assoc' :: HyperA (K m) (a, (b, c)) ((a, b), c) Source #

slide :: HyperA (K m) (a, (b, c)) (b, (a, c)) Source #

Monad m => Strength Either (K m :: Type -> Type -> Type) Source #

Traced for K m with the Either tensor, for any Monad m.

Iterates by feeding Left back into the step function until a Right is produced. Uses plain recursion — builds stack proportional to iteration count.

>>> :{
let countTo target = K $ \case
      Left n | n < target -> pure (Left (n + 1))
             | otherwise  -> pure (Right n)
      Right ()            -> pure (Left 0)
:}
>>> runK (trace (countTo (3 :: Int))) ()
3

This instance is OVERLAPPABLE: the IO-specific instance below takes priority for IO, providing constant-stack iteration via delimited continuations.

Instance details

Defined in Circuit.Channel

Methods

strength :: K m b c -> K m (Either a b) (Either a c) Source #

Monad m => Strength These (K m :: Type -> Type -> Type) Source #

Inclusive tensorial strength for K m with These.

Instance details

Defined in Circuit.Channel

Methods

strength :: K m b c -> K m (These a b) (These a c) Source #

Monad m => Strength (,) (K m :: Type -> Type -> Type) Source #

Traced for K m with the cartesian tensor, requiring MonadFix m.

The lazy knot is tied via mfix. The feedback channel is lazy in the recursive binding — the body must not force the feedback value before producing it, or mfix will diverge (just as the pure (,) trace black-holes on strict fields).

>>> :{
let fibs = K $ \(fibs, ()) ->
      pure (0 : 1 : zipWith (+) fibs (drop 1 fibs), take 3 fibs)
:}
>>> runK (trace fibs) ()
[0,1,1]
Instance details

Defined in Circuit.Channel

Methods

strength :: K m b c -> K m (a, b) (a, c) Source #

Monad m => Strength (,) (HyperA (K m) :: Type -> Type -> Type) Source # 
Instance details

Defined in Circuit.Hyper

Methods

strength :: HyperA (K m) b c -> HyperA (K m) (a, b) (a, c) Source #

Traced Either (K IO) Source #

Traced for K IO with Either tensor.

Each iteration re-establishes the prompt boundary. When control0 fires on Left a, it captures the continuation, wraps it around the next loop step, and jumps back to the prompt — constant stack.

>>> :{
let exit42 = K $ \case
      Right () -> pure (Right (42 :: Int))
:}
>>> runK (trace exit42) ()
42
Instance details

Defined in Circuit.Channel

Methods

trace :: K IO (Either a b) (Either a c) -> K IO b c Source #

Monad m => Traced Either (K m :: Type -> Type -> Type) Source # 
Instance details

Defined in Circuit.Channel

Methods

trace :: K m (Either a b) (Either a c) -> K m b c Source #

MonadFix m => Traced (,) (K m :: Type -> Type -> Type) Source # 
Instance details

Defined in Circuit.Channel

Methods

trace :: K m (a, b) (a, c) -> K m b c Source #

MonadFix m => Traced (,) (HyperA (K m) :: Type -> Type -> Type) Source # 
Instance details

Defined in Circuit.Hyper

Methods

trace :: HyperA (K m) (a, b) (a, c) -> HyperA (K m) b c Source #

Monad m => Par Either (K m :: Type -> Type -> Type) Source #

Coproduct as multiplicative disjunction on K arrows.

Instance details

Defined in Circuit.Par

Methods

parP :: K m a b -> K m c d -> K m (Either a c) (Either b d) Source #

unitlP :: K m (Either (Bot Either) a) a Source #

unitlP' :: K m a (Either (Bot Either) a) Source #

unitrP :: K m (Either a (Bot Either)) a Source #

unitrP' :: K m a (Either a (Bot Either)) Source #

Monad m => HasDual () (K m :: Type -> Type -> Type) Source #

Dualising object () for K m.

Same shape as the (->) instance, but the constant companion returns () in the monad.

Instance details

Defined in Circuit.Poles

Methods

open :: Poles (K m) () () Source #

Monad m => HasDual Bool (K m :: Type -> Type -> Type) Source #

Dualising object Bool for K m.

Same shape as the (->) instance, but the constant companion returns False in the monad.

Instance details

Defined in Circuit.Poles

Methods

open :: Poles (K m) Bool Bool Source #

Monad m => Action Either (K m :: Type -> Type -> Type) Source #

Coproduct symmetry on K m.

Instance details

Defined in Circuit.Tensor

Methods

braid :: K m (Either a b) (Either b a) Source #

Monad m => Action These (K m :: Type -> Type -> Type) Source #

Inclusive symmetry on K m.

Instance details

Defined in Circuit.Tensor

Methods

braid :: K m (These a b) (These b a) Source #

Monad m => Action (,) (K m :: Type -> Type -> Type) Source # 
Instance details

Defined in Circuit.Tensor

Methods

braid :: K m (a, b) (b, a) Source #

Monad m => Tensor Either (K m :: Type -> Type -> Type) Source #

Coproduct tensor action on K m.

>>> import Circuit.Category (K(..), runK)
>>> let f = K (\n -> pure (n + 1)) :: K IO Int Int
>>> let g = K (\n -> pure (n * 2)) :: K IO Int Int
>>> runK (tensor f g) (Left 3 :: Either Int Int)
Left 4
>>> runK (tensor f g) (Right 3 :: Either Int Int)
Right 6
Instance details

Defined in Circuit.Tensor

Methods

tensor :: K m a b -> K m c d -> K m (Either a c) (Either b d) Source #

Monad m => Tensor These (K m :: Type -> Type -> Type) Source #

Inclusive tensor action on K m.

Instance details

Defined in Circuit.Tensor

Methods

tensor :: K m a b -> K m c d -> K m (These a c) (These b d) Source #

Monad m => Tensor (,) (K m :: Type -> Type -> Type) Source #

Cartesian tensor on K (effectful sequential product).

Instance details

Defined in Circuit.Tensor

Methods

tensor :: K m a b -> K m c d -> K m (a, c) (b, d) Source #

Monad m => Unital Either (K m :: Type -> Type -> Type) Source #

Coproduct unit structure on K m.

Instance details

Defined in Circuit.Tensor

Methods

unitl :: K m (Either (Unit Either) a) a Source #

unitl' :: K m a (Either (Unit Either) a) Source #

unitr :: K m (Either a (Unit Either)) a Source #

unitr' :: K m a (Either a (Unit Either)) Source #

Monad m => Unital These (K m :: Type -> Type -> Type) Source #

Inclusive unit structure on K m.

Instance details

Defined in Circuit.Tensor

Methods

unitl :: K m (These (Unit These) a) a Source #

unitl' :: K m a (These (Unit These) a) Source #

unitr :: K m (These a (Unit These)) a Source #

unitr' :: K m a (These a (Unit These)) Source #

Monad m => Unital (,) (K m :: Type -> Type -> Type) Source #

Cartesian unit structure on K (effectful sequential product).

Instance details

Defined in Circuit.Tensor

Methods

unitl :: K m (Unit (,), a) a Source #

unitl' :: K m a (Unit (,), a) Source #

unitr :: K m (a, Unit (,)) a Source #

unitr' :: K m a (a, Unit (,)) Source #

(Monad m, Pointed s) => HasDual Void (Body Either s (K m) :: Type -> Type -> Type) Source #

Unit poles for Body Either s (K m) at Void.

Instance details

Defined in Circuit.Body

Methods

open :: Poles (Body Either s (K m)) Void Void Source #

Monad m => HasDual () (Body (,) s (K m) :: Type -> Type -> Type) Source #

Unit poles for Body (,) s (K m).

Same shape as the (->) instance, but the companion returns () in the monad and threads the ambient state through unchanged.

Instance details

Defined in Circuit.Body

Methods

open :: Poles (Body (,) s (K m)) () () Source #

Monad m => Category (K m :: Type -> Type -> Type) Source # 
Instance details

Defined in Circuit.Category

Methods

id :: K m a a Source #

(.) :: K m b c -> K m a b -> K m a c Source #

Monad m => Category (HyperA (K m) :: Type -> Type -> Type) Source # 
Instance details

Defined in Circuit.Hyper

Methods

id :: HyperA (K m) a a Source #

(.) :: HyperA (K m) b c -> HyperA (K m) a b -> HyperA (K m) a c Source #

Monad m => Shared (,) (K m) Source #

Cartesian shared fusion on K arrows.

Instance details

Defined in Circuit.Shared

Methods

sharedBy :: Schedule s -> K m (s, a) (s, b) -> K m (s, c) (s, d) -> K m (s, (a, c)) (s, These b d) Source #

Monad m => FunctionLike (K m) Source #

Kleisli arrows embed pure functions by returning the result in the monad.

Instance details

Defined in Circuit.Category

Methods

function :: (a -> b) -> K m a b Source #

class Category arr => FunctionLike (arr :: Type -> Type -> Type) where Source #

Categories that can embed pure functions as morphisms.

This is the canonical functor from the function category (->) into arr. It is useful for lifting decision procedures (e.g. bias in a race) into arrows such as Kleisli categories.

Methods

function :: (a -> b) -> arr a b Source #

Lift a pure function into the arrow.

Instances

Instances details
Monad m => FunctionLike (K m) Source #

Kleisli arrows embed pure functions by returning the result in the monad.

Instance details

Defined in Circuit.Category

Methods

function :: (a -> b) -> K m a b Source #

FunctionLike (->) Source #

Functions embed as themselves.

Instance details

Defined in Circuit.Category

Methods

function :: (a -> b) -> a -> b Source #

class Pointed a where Source #

A pointed object: an object with a distinguished element.

This class has no laws by construction — it merely names a chosen element. It is the structural requirement for the coproduct-unit poles of 'Body Either': on a payload input the companion must produce a carrier value, and there is no ambient state to use. Monoid is over-strong for this purpose, since only the identity element is needed.

Methods

point :: a Source #

Instances

Instances details
Pointed () Source #

The singleton type is canonically pointed.

Instance details

Defined in Circuit.Category

Methods

point :: () Source #

Pointed (Maybe a) Source #

Maybe is canonically pointed at Nothing.

Instance details

Defined in Circuit.Category

Methods

point :: Maybe a Source #

Pointed [a] Source #

Lists are canonically pointed at the empty list.

Instance details

Defined in Circuit.Category

Methods

point :: [a] Source #