proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Category.Instance.Circuit

Description

Synchronous digital circuits. The tensor preserves the grouping of bit bundles; copying is fan-out, and tracing connects wires without adding a delay. register delays a bit by one clock cycle. prepare rejects observable combinational cycles before simulation.

>>> simulate notGate [False, True]
Right [True,False]
>>> simulate (register False) [True, False, True]
Right [False,True,False]
Synopsis

Documentation

data Wires Source Github #

A bit, no wires, or two bundles. Tensor grouping is retained in the type.

Constructors

Bit 
Empty 
Pair Wires Wires 

Instances

Instances details
Monoidal Wires Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Associated Types

type Unit 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Unit = 'Empty
type (a :: Wires) ** (b :: Wires) 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type (a :: Wires) ** (b :: Wires) = 'Pair a b

Methods

withOb2 :: forall (a :: Wires) (b :: Wires) r. (Ob a, Ob b) => (Ob (a ** b) => r) -> r Source Github #

leftUnitor :: forall (a :: Wires). Ob a => ((Unit :: Wires) ** a) ~> a Source Github #

leftUnitorInv :: forall (a :: Wires). Ob a => a ~> ((Unit :: Wires) ** a) Source Github #

rightUnitor :: forall (a :: Wires). Ob a => (a ** (Unit :: Wires)) ~> a Source Github #

rightUnitorInv :: forall (a :: Wires). Ob a => a ~> (a ** (Unit :: Wires)) Source Github #

associator :: forall (a :: Wires) (b :: Wires) (c :: Wires). (Ob a, Ob b, Ob c) => ((a ** b) ** c) ~> (a ** (b ** c)) Source Github #

associatorInv :: forall (a :: Wires) (b :: Wires) (c :: Wires). (Ob a, Ob b, Ob c) => (a ** (b ** c)) ~> ((a ** b) ** c) Source Github #

SymMonoidal Wires Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

swap :: forall (a :: Wires) (b :: Wires). (Ob a, Ob b) => (a ** b) ~> (b ** a) Source Github #

CopyDiscard Wires Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

copy :: forall (a :: Wires). Ob a => a ~> (a ** a) Source Github #

discard :: forall (a :: Wires). Ob a => a ~> (Unit :: Wires) Source Github #

CategoryOf Wires Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Associated Types

type (~>) 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type (~>) = Circuit
type Ob (a :: Wires) 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Ob (a :: Wires) = KnownWires a
Promonad Circuit Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

id :: forall (a :: Wires). Ob a => Circuit a a Source Github #

(.) :: forall (b :: Wires) (c :: Wires) (a :: Wires). Circuit b c -> Circuit a b -> Circuit a c Source Github #

KnownWires a => CocommutativeComonoid (a :: Wires) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

KnownWires a => Comonoid (a :: Wires) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

counit :: a ~> (Unit :: Wires) Source Github #

comult :: a ~> (a ** a) Source Github #

MonoidalProfunctor Circuit Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

one :: Circuit (Unit :: Wires) (Unit :: Wires) Source Github #

(**) :: forall (x1 :: Wires) (x2 :: Wires) (y1 :: Wires) (y2 :: Wires). Circuit x1 x2 -> Circuit y1 y2 -> Circuit (x1 ** y1) (x2 ** y2) Source Github #

Profunctor Circuit Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

dimap :: forall (c :: Wires) (a :: Wires) (b :: Wires) (d :: Wires). (c ~> a) -> (b ~> d) -> Circuit a b -> Circuit c d Source Github #

lmap :: forall (c :: Wires) (a :: Wires) (b :: Wires). (c ~> a) -> Circuit a b -> Circuit c b Source Github #

rmap :: forall (b :: Wires) (d :: Wires) (a :: Wires). (b ~> d) -> Circuit a b -> Circuit a d Source Github #

(\\) :: forall (a :: Wires) (b :: Wires) r. ((Ob a, Ob b) => r) -> Circuit a b -> r Source Github #

Costrong (Tensor :: Wires -> (Wires, Wires) -> Type) Circuit Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

coact :: forall (a :: Wires) (x :: Wires) (y :: Wires). (Ob a, Ob x, Ob y) => Circuit (Act (Tensor :: Wires -> (Wires, Wires) -> Type) a x) (Act (Tensor :: Wires -> (Wires, Wires) -> Type) a y) -> Circuit x y Source Github #

type Unit Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Unit = 'Empty
type (~>) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type (~>) = Circuit
type Ob (a :: Wires) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Ob (a :: Wires) = KnownWires a
type (a :: Wires) ** (b :: Wires) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type (a :: Wires) ** (b :: Wires) = 'Pair a b

class Is 'Sim (Value @ 'Ready a) => KnownWires (a :: Wires) Source Github #

Minimal complete definition

shape

Instances

Instances details
KnownWires 'Bit Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

shape :: Shape 'Bit

KnownWires 'Empty Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

shape :: Shape 'Empty

(KnownWires a, KnownWires b) => KnownWires ('Pair a b) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

shape :: Shape ('Pair a b)

data family Value :: PREPARED +-> SIMULATOR Source Github #

Interpret validated circuits as state machines. Bits become Bool, the unit becomes (), and a tensor becomes a pair, all in the SIMULATOR category.

Instances

Instances details
FunctorForRep Value Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Associated Types

type Value @ ('Ready 'Bit) 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Value @ ('Ready 'Bit) = 'Sim Bool
type Value @ ('Ready 'Empty) 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Value @ ('Ready 'Empty) = 'Sim ()
type Value @ ('Ready ('Pair a b) :: PREPARED) 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Value @ ('Ready ('Pair a b) :: PREPARED) = 'Sim (Sample a, Sample b)

Methods

fmap :: forall (a :: PREPARED) (b :: PREPARED). (a ~> b) -> (Value @ a) ~> (Value @ b) Source Github #

MonoidalProfunctor (Rep Value) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

one :: Rep Value (Unit :: SIMULATOR) (Unit :: PREPARED) Source Github #

(**) :: forall (x1 :: SIMULATOR) (x2 :: PREPARED) (y1 :: SIMULATOR) (y2 :: PREPARED). Rep Value x1 x2 -> Rep Value y1 y2 -> Rep Value (x1 ** y1) (x2 ** y2) Source Github #

type Value @ ('Ready 'Bit) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Value @ ('Ready 'Bit) = 'Sim Bool
type Value @ ('Ready 'Empty) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Value @ ('Ready 'Empty) = 'Sim ()
type Value @ ('Ready ('Pair a b) :: PREPARED) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Value @ ('Ready ('Pair a b) :: PREPARED) = 'Sim (Sample a, Sample b)

type Sample (a :: Wires) = UN 'Sim (Value @ 'Ready a) Source Github #

The Haskell value for one clock cycle at a wire shape.

data PREPARED Source Github #

Objects of validated circuits, with the same wire shapes as Wires.

Constructors

Ready Wires 

Instances

Instances details
Monoidal PREPARED Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Associated Types

type Unit 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Unit = 'Ready 'Empty
type (a :: PREPARED) ** (b :: PREPARED) 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type (a :: PREPARED) ** (b :: PREPARED) = 'Ready ('Pair (UN 'Ready a) (UN 'Ready b))

Methods

withOb2 :: forall (a :: PREPARED) (b :: PREPARED) r. (Ob a, Ob b) => (Ob (a ** b) => r) -> r Source Github #

leftUnitor :: forall (a :: PREPARED). Ob a => ((Unit :: PREPARED) ** a) ~> a Source Github #

leftUnitorInv :: forall (a :: PREPARED). Ob a => a ~> ((Unit :: PREPARED) ** a) Source Github #

rightUnitor :: forall (a :: PREPARED). Ob a => (a ** (Unit :: PREPARED)) ~> a Source Github #

rightUnitorInv :: forall (a :: PREPARED). Ob a => a ~> (a ** (Unit :: PREPARED)) Source Github #

associator :: forall (a :: PREPARED) (b :: PREPARED) (c :: PREPARED). (Ob a, Ob b, Ob c) => ((a ** b) ** c) ~> (a ** (b ** c)) Source Github #

associatorInv :: forall (a :: PREPARED) (b :: PREPARED) (c :: PREPARED). (Ob a, Ob b, Ob c) => (a ** (b ** c)) ~> ((a ** b) ** c) Source Github #

SymMonoidal PREPARED Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

swap :: forall (a :: PREPARED) (b :: PREPARED). (Ob a, Ob b) => (a ** b) ~> (b ** a) Source Github #

CopyDiscard PREPARED Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

copy :: forall (a :: PREPARED). Ob a => a ~> (a ** a) Source Github #

discard :: forall (a :: PREPARED). Ob a => a ~> (Unit :: PREPARED) Source Github #

CategoryOf PREPARED Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Associated Types

type (~>) 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type (~>) = Prepared
type Ob (a :: PREPARED) 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Ob (a :: PREPARED) = (Is 'Ready a, KnownWires (UN 'Ready a))
Promonad Prepared Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

id :: forall (a :: PREPARED). Ob a => Prepared a a Source Github #

(.) :: forall (b :: PREPARED) (c :: PREPARED) (a :: PREPARED). Prepared b c -> Prepared a b -> Prepared a c Source Github #

Ob a => CocommutativeComonoid (a :: PREPARED) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Ob a => Comonoid (a :: PREPARED) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

counit :: a ~> (Unit :: PREPARED) Source Github #

comult :: a ~> (a ** a) Source Github #

MonoidalProfunctor Prepared Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

one :: Prepared (Unit :: PREPARED) (Unit :: PREPARED) Source Github #

(**) :: forall (x1 :: PREPARED) (x2 :: PREPARED) (y1 :: PREPARED) (y2 :: PREPARED). Prepared x1 x2 -> Prepared y1 y2 -> Prepared (x1 ** y1) (x2 ** y2) Source Github #

Profunctor Prepared Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

dimap :: forall (c :: PREPARED) (a :: PREPARED) (b :: PREPARED) (d :: PREPARED). (c ~> a) -> (b ~> d) -> Prepared a b -> Prepared c d Source Github #

lmap :: forall (c :: PREPARED) (a :: PREPARED) (b :: PREPARED). (c ~> a) -> Prepared a b -> Prepared c b Source Github #

rmap :: forall (b :: PREPARED) (d :: PREPARED) (a :: PREPARED). (b ~> d) -> Prepared a b -> Prepared a d Source Github #

(\\) :: forall (a :: PREPARED) (b :: PREPARED) r. ((Ob a, Ob b) => r) -> Prepared a b -> r Source Github #

FunctorForRep Value Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Associated Types

type Value @ ('Ready 'Bit) 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Value @ ('Ready 'Bit) = 'Sim Bool
type Value @ ('Ready 'Empty) 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Value @ ('Ready 'Empty) = 'Sim ()
type Value @ ('Ready ('Pair a b) :: PREPARED) 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Value @ ('Ready ('Pair a b) :: PREPARED) = 'Sim (Sample a, Sample b)

Methods

fmap :: forall (a :: PREPARED) (b :: PREPARED). (a ~> b) -> (Value @ a) ~> (Value @ b) Source Github #

MonoidalProfunctor (Rep Value) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

one :: Rep Value (Unit :: SIMULATOR) (Unit :: PREPARED) Source Github #

(**) :: forall (x1 :: SIMULATOR) (x2 :: PREPARED) (y1 :: SIMULATOR) (y2 :: PREPARED). Rep Value x1 x2 -> Rep Value y1 y2 -> Rep Value (x1 ** y1) (x2 ** y2) Source Github #

type Unit Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Unit = 'Ready 'Empty
type (~>) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type (~>) = Prepared
type Ob (a :: PREPARED) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Ob (a :: PREPARED) = (Is 'Ready a, KnownWires (UN 'Ready a))
type (a :: PREPARED) ** (b :: PREPARED) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type (a :: PREPARED) ** (b :: PREPARED) = 'Ready ('Pair (UN 'Ready a) (UN 'Ready b))
type Value @ ('Ready 'Bit) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Value @ ('Ready 'Bit) = 'Sim Bool
type Value @ ('Ready 'Empty) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Value @ ('Ready 'Empty) = 'Sim ()
type Value @ ('Ready ('Pair a b) :: PREPARED) Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

type Value @ ('Ready ('Pair a b) :: PREPARED) = 'Sim (Sample a, Sample b)

data Prepared (a :: PREPARED) (b :: PREPARED) Source Github #

A circuit that passed combinational-cycle validation, carrying its current simulation state. Composition and tensor preserve validity; unrestricted trace is available only before validation.

Instances

Instances details
Promonad Prepared Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

id :: forall (a :: PREPARED). Ob a => Prepared a a Source Github #

(.) :: forall (b :: PREPARED) (c :: PREPARED) (a :: PREPARED). Prepared b c -> Prepared a b -> Prepared a c Source Github #

MonoidalProfunctor Prepared Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

one :: Prepared (Unit :: PREPARED) (Unit :: PREPARED) Source Github #

(**) :: forall (x1 :: PREPARED) (x2 :: PREPARED) (y1 :: PREPARED) (y2 :: PREPARED). Prepared x1 x2 -> Prepared y1 y2 -> Prepared (x1 ** y1) (x2 ** y2) Source Github #

Profunctor Prepared Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

dimap :: forall (c :: PREPARED) (a :: PREPARED) (b :: PREPARED) (d :: PREPARED). (c ~> a) -> (b ~> d) -> Prepared a b -> Prepared c d Source Github #

lmap :: forall (c :: PREPARED) (a :: PREPARED) (b :: PREPARED). (c ~> a) -> Prepared a b -> Prepared c b Source Github #

rmap :: forall (b :: PREPARED) (d :: PREPARED) (a :: PREPARED). (b ~> d) -> Prepared a b -> Prepared a d Source Github #

(\\) :: forall (a :: PREPARED) (b :: PREPARED) r. ((Ob a, Ob b) => r) -> Prepared a b -> r Source Github #

data Circuit (a :: Wires) (b :: Wires) Source Github #

A typed circuit builder. Constructors are hidden so every output bit has one driver.

Instances

Instances details
Promonad Circuit Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

id :: forall (a :: Wires). Ob a => Circuit a a Source Github #

(.) :: forall (b :: Wires) (c :: Wires) (a :: Wires). Circuit b c -> Circuit a b -> Circuit a c Source Github #

MonoidalProfunctor Circuit Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

one :: Circuit (Unit :: Wires) (Unit :: Wires) Source Github #

(**) :: forall (x1 :: Wires) (x2 :: Wires) (y1 :: Wires) (y2 :: Wires). Circuit x1 x2 -> Circuit y1 y2 -> Circuit (x1 ** y1) (x2 ** y2) Source Github #

Profunctor Circuit Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

dimap :: forall (c :: Wires) (a :: Wires) (b :: Wires) (d :: Wires). (c ~> a) -> (b ~> d) -> Circuit a b -> Circuit c d Source Github #

lmap :: forall (c :: Wires) (a :: Wires) (b :: Wires). (c ~> a) -> Circuit a b -> Circuit c b Source Github #

rmap :: forall (b :: Wires) (d :: Wires) (a :: Wires). (b ~> d) -> Circuit a b -> Circuit a d Source Github #

(\\) :: forall (a :: Wires) (b :: Wires) r. ((Ob a, Ob b) => r) -> Circuit a b -> r Source Github #

Costrong (Tensor :: Wires -> (Wires, Wires) -> Type) Circuit Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Circuit

Methods

coact :: forall (a :: Wires) (x :: Wires) (y :: Wires). (Ob a, Ob x, Ob y) => Circuit (Act (Tensor :: Wires -> (Wires, Wires) -> Type) a x) (Act (Tensor :: Wires -> (Wires, Wires) -> Type) a y) -> Circuit x y Source Github #

constant :: Bool -> 'Empty ~> 'Bit Source Github #

A constant bit, independent of the clock.

mux :: (('Bit ** 'Bit) ** 'Bit) ~> 'Bit Source Github #

Select the second input when the first is true, and the third when it is false.

register :: Bool -> 'Bit ~> 'Bit Source Github #

A register's output starts at the given value. Each clock edge replaces it with its input from the preceding cycle. All registers update simultaneously.

data Netlist (a :: Wires) (b :: Wires) Source Github #

A netlist with typed boundaries. Disconnected components are omitted.

netlist :: forall (a :: Wires) (b :: Wires). Circuit a b -> Netlist a b Source Github #

Build a netlist, retaining precisely the components that can influence an output, including through a register on a later cycle.

renderNetlist :: forall (a :: Wires) (b :: Wires). Netlist a b -> String Source Github #

A text netlist. Bit numbers are local to this netlist; bundle ports are ordered left to right.

toDot :: forall (a :: Wires) (b :: Wires). Netlist a b -> String Source Github #

A Graphviz graph of the same netlist used by the simulator. Register nodes show their initial value. Copying is fan-out of an edge, and feedback aliases are small connection points.

toVerilog :: forall (a :: Wires) (b :: Wires). String -> Netlist a b -> Either CircuitError String Source Github #

Verilog with scalar ports in0, in1, ... and out0, out1, ... in bundle order, and a shared rising-edge clock clk. The caller supplies a valid Verilog module name. Combinational cycles are rejected, and disconnected components are omitted.

Registers use initial assignments to preserve their starting values in simulation; synthesis support for initialization depends on the hardware target.

newtype CircuitError Source Github #

Bits participating in a combinational cycle. Every observable cycle must cross a register.

Constructors

CombinationalCycle [Int] 

data Simulator (a :: SIMULATOR) (b :: SIMULATOR) Source Github #

A machine and its current state, represented by its next step.

Instances

Instances details
Promonad Simulator Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Simulator

Methods

id :: forall (a :: SIMULATOR). Ob a => Simulator a a Source Github #

(.) :: forall (b :: SIMULATOR) (c :: SIMULATOR) (a :: SIMULATOR). Simulator b c -> Simulator a b -> Simulator a c Source Github #

MonoidalProfunctor Simulator Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Simulator

Methods

one :: Simulator (Unit :: SIMULATOR) (Unit :: SIMULATOR) Source Github #

(**) :: forall (x1 :: SIMULATOR) (x2 :: SIMULATOR) (y1 :: SIMULATOR) (y2 :: SIMULATOR). Simulator x1 x2 -> Simulator y1 y2 -> Simulator (x1 ** y1) (x2 ** y2) Source Github #

Profunctor Simulator Source Github # 
Instance details

Defined in Proarrow.Category.Instance.Simulator

Methods

dimap :: forall (c :: SIMULATOR) (a :: SIMULATOR) (b :: SIMULATOR) (d :: SIMULATOR). (c ~> a) -> (b ~> d) -> Simulator a b -> Simulator c d Source Github #

lmap :: forall (c :: SIMULATOR) (a :: SIMULATOR) (b :: SIMULATOR). (c ~> a) -> Simulator a b -> Simulator c b Source Github #

rmap :: forall (b :: SIMULATOR) (d :: SIMULATOR) (a :: SIMULATOR). (b ~> d) -> Simulator a b -> Simulator a d Source Github #

(\\) :: forall (a :: SIMULATOR) (b :: SIMULATOR) r. ((Ob a, Ob b) => r) -> Simulator a b -> r Source Github #

prepare :: forall (a :: Wires) (b :: Wires). Netlist a b -> Either CircuitError (Prepared ('Ready a) ('Ready b)) Source Github #

Cut the dependencies through registers and topologically order the combinational nodes. Multiplexers depend on both data inputs, even when their selector is constant.

step :: Simulator ('Sim a) ('Sim b) -> a -> (b, Simulator ('Sim a) ('Sim b)) Source Github #

Observe the current output and advance one clock cycle.

simulate :: forall (a :: Wires) (b :: Wires). Circuit a b -> [Sample a] -> Either CircuitError [Sample b] Source Github #

Prepare a circuit once and simulate a sequence of clock cycles. Each output is observed before the clock edge for the corresponding input.