[Haskell-cafe] Desugaring ArrowLoop notation

Francesco Ariis fa-ml at ariis.it
Sat Jan 28 14:42:07 UTC 2017


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!


More information about the Haskell-Cafe mailing list