
28 Jan
2017
28 Jan
'17
2:42 p.m.
On Sat, Jan 28, 2017 at 03:07:48PM +0100, Ertugrul Söylemez wrote:
mean5 :: Fractional a => Circuit a a mean5 = proc value -> do rec (lastTot, lastN) <- delay (0,0) -< (tot, n) let (tot, n) = (lastTot + value, lastN + 1) let mean = tot / n returnA -< mean
So I ask: what's the sour version of `mean5`?
The translation is very similar to the one for 'mfix', except that you need to account for the side channel in the input:
mean5 = loop $ proc (value, ~(tot', n')) -> do (lastTot, lastN) <- delay (0,0) -< (tot', n') let (tot, n) = (lastTot + value, lastN + 1) id -< (tot / n, (tot, n))
Thank you, loop machinery is much more clearer now!