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))