moore is:exact

Create a synchronous function from a combinational function describing a moore machine
macT
:: Int        -- Current state
-> (Int,Int)  -- Input
-> (Int,Int)  -- Updated state
macT s (x,y) = x * y + s

mac
:: KnownDomain dom
=> Clock dom
-> Reset dom
-> Enable dom
-> Signal dom (Int, Int)
-> Signal dom Int
mac clk rst en = moore clk rst en macT id 0
>>> simulate (mac systemClockGen systemResetGen enableGen) [(0,0),(1,1),(2,2),(3,3),(4,4)]
[0,0,1,5,14...
...
Synchronous sequential functions can be composed just like their combinational counterpart:
dualMac
:: KnownDomain dom
=> Clock dom
-> Reset dom
-> Enable dom
-> (Signal dom Int, Signal dom Int)
-> (Signal dom Int, Signal dom Int)
-> Signal dom Int
dualMac clk rst en (a,b) (x,y) = s1 + s2
where
s1 = moore clk rst en macT id 0 (bundle (a,x))
s2 = moore clk rst en macT id 0 (bundle (b,y))
Create a synchronous function from a combinational function describing a moore machine
macT
:: Int        -- Current state
-> (Int,Int)  -- Input
-> Int        -- Updated state
macT s (x,y) = x * y + s

mac
:: HiddenClockResetEnable dom
=> Signal dom (Int, Int)
-> Signal dom Int
mac = moore mac id 0
>>> simulate @System mac [(0,0),(1,1),(2,2),(3,3),(4,4)]
[0,0,1,5,14,30,...
...
Synchronous sequential functions can be composed just like their combinational counterpart:
dualMac
:: HiddenClockResetEnable dom
=> (Signal dom Int, Signal dom Int)
-> (Signal dom Int, Signal dom Int)
-> Signal dom Int
dualMac (a,b) (x,y) = s1 + s2
where
s1 = moore macT id 0 (bundle (a,x))
s2 = moore macT id 0 (bundle (b,y))