[Haskell-cafe] How to implement digital filters using Arrows

Captain Freako capn.freako at gmail.com
Mon Oct 31 16:05:06 CET 2011


Hi John,

Thanks for all your help.
I've been studying your suggested code:

> type FilterAu b c = Automaton (->) b c

 > liftAu :: ((x,FilterState s)->(y,FilterState s)) -> FilterState s ->
FilterAu x y
 > liftAu f s0 = proc x -> do
 >    rec (y,s') <- arr f -< (x,s)
 >        s <- delay s0 -< s'
 >    returnA -< y


runAutomaton is a bit cumbersome, so define a custom run function that
takes a list

 > runAuto a             []     = []
 > runAuto (Automaton f) (x:xs) = let
 >   (y,a) = f xt
 >   in y:runAuto a xs

as well as the various instance definitions for Automaton.

I think I understand how the `returnA' in the last line of your
`liftAu' function is getting translated by those instance definitions
into:

c where
c = Automaton ( arr id &&& arr (const c) )

and, furthermore, how that is passing the supplied `y' into the first
element of the resulting couple. However, I don't understand how the
recursively defined `c' is capturing the modified filter state and
preserving it for the next call. It seems like the Automaton being
referred to by `c' is a newly constructed entity, which knows nothing
about the current state of the running Automaton.

Any help in understanding this would be greatly appreciated.

Thanks!
-db



More information about the Haskell-Cafe mailing list