circuits
Safe HaskellNone
LanguageGHC2024

Circuit.Shared

Description

Shared-medium fusion: two bodies interleaved on one shared channel.

The connective here is the multiplicative disjunction in operational form: two sub-loops share a single channel, and a Schedule resolves the interleaving. This is the mixed-mode counterpart to superpose, which keeps channels independent (the product).

Bias is re-exported from Circuit.Tensor because it is also used for additive disjunction in Circuit.Poles.

Synopsis

Schedule bias

data Bias Source #

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 

Instances

Instances details
Eq Bias Source # 
Instance details

Defined in Circuit.Tensor

Methods

(==) :: Bias -> Bias -> Bool #

(/=) :: Bias -> Bias -> Bool #

Show Bias Source # 
Instance details

Defined in Circuit.Tensor

Methods

showsPrec :: Int -> Bias -> ShowS #

show :: Bias -> String #

showList :: [Bias] -> ShowS #

Schedule decision

data Pick Source #

A schedule decision: which poles advance on a shared channel.

  • L — advance the left body only; the right input is not consumed (corresponds to This).
  • R — advance the right body only; the left input is not consumed (corresponds to That).
  • Both b — advance both bodies, with the bias choosing the order (corresponds to These).

Constructors

L 
R 
Both Bias 

Instances

Instances details
Eq Pick Source # 
Instance details

Defined in Circuit.Shared

Methods

(==) :: Pick -> Pick -> Bool #

(/=) :: Pick -> Pick -> Bool #

Show Pick Source # 
Instance details

Defined in Circuit.Shared

Methods

showsPrec :: Int -> Pick -> ShowS #

show :: Pick -> String #

showList :: [Pick] -> ShowS #

Schedule driver

newtype Schedule s Source #

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.

Constructors

Schedule 

Fields

  • chooseS :: s -> (s, Pick)

    Given the current shared state, return the updated state and a Pick value describing which poles advance and in what order.

Shared fusion class

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.

Instances

Instances details
Shared (,) Process Source #

Cartesian shared fusion on processes.

The two processes share one feedback channel s. At each tick the schedule chooses which body advances; the gated body's input is discarded and it does not step. Each process is injected lazily on its first firing, so a body that is never scheduled consumes no inputs and produces no outputs.

Instance details

Defined in Circuit.Process

Methods

sharedBy :: Schedule s -> Process (s, a) (s, b) -> Process (s, c) (s, d) -> Process (s, (a, c)) (s, These b d) 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 #

Shared (,) (->) Source #

Cartesian shared fusion on functions.

The schedule chooses which bodies advance and in what order. L/R run only the chosen body and emit a partial This/That product; the other body's input is discarded. Both LeftFirst / Both RightFirst run both bodies, threading the shared state in the chosen order, and emit a total These product. When both bodies read and write s, the two orders are observationally different — this is the ⅋-vs-⊗ distinction.

Instance details

Defined in Circuit.Shared

Methods

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

Shared-medium fusion signature

data SigShared (t :: Type -> Type -> Type) (arr :: k) (rec :: Type -> Type -> Type) i o where Source #

Shared-medium fusion (the tensor product ⅋), parameterised by a schedule.

The constructor takes two bodies that already share a feedback type s and produces the untraced shared body. The surrounding SigYank closes the feedback loop over s, yielding a morphism t a c -> These b d.

Constructors

SigShared :: forall {k} s (rec :: Type -> Type -> Type) (t :: Type -> Type -> Type) a b c d (arr :: k). Schedule s -> rec (t s a) (t s b) -> rec (t s c) (t s d) -> SigShared t arr rec (t s (t a c)) (t s (These b d)) 

Instances

Instances details
Shared t arr' => Algebra (SigShared t :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) arr arr' Source # 
Instance details

Defined in Circuit.Shared

Associated Types

type Ctx (SigShared t :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) arr arr' 
Instance details

Defined in Circuit.Shared

type Ctx (SigShared t :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) arr arr' = Shared t arr'

Methods

alg :: Ctx (SigShared t :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) arr arr' => (forall x y. arr x y -> arr' x y) -> (forall x y. rec x y -> arr' x y) -> SigShared t arr rec a b -> arr' a b Source #

type Ctx (SigShared t :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) arr arr' Source # 
Instance details

Defined in Circuit.Shared

type Ctx (SigShared t :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) arr arr' = Shared t arr'

Free traced category with shared-medium fusion

type AlgShared (t :: Type -> Type -> Type) (arr :: Type -> Type -> Type) = Syntax ((SigCompose :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: ((SigShared t :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type) :+: (SigYank t :: (Type -> Type -> Type) -> (Type -> Type -> Type) -> Type -> Type -> Type))) arr Source #

Free traced category with shared-medium fusion (the ⅋ connective).