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

2011-11-01 Thread Captain Freako
On Mon, Oct 31, 2011 at 3:19 PM, John Lask jvl...@hotmail.com wrote: On 1/11/2011 1:35 AM, Captain Freako wrote: you need to study ArrowLoop and understand that. Thanks, John. I'm working my way through Hughes' suggested exercise in `Programming with Arrows', to wit: The reader who finds

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

2011-11-01 Thread Captain Freako
Hi John, I'm trying to use the GHCI debugger on this code: 20 instance ArrowLoop SF where 21 loop (SF f) = SF $ \as - 22 let (bs, cs) = unzip (f (zip as (stream cs))) in bs 23 where stream ~(x:xs) = x : stream xs 24 25 swap :: (a,b) - (b,a) 26 swap (x,y) = (y,x) in

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

2011-11-01 Thread Ryan Ingram
Try swap p = (snd p, fst p) or, equivalently swap ~(x,y) = (y,x) -- ryan On Tue, Nov 1, 2011 at 1:30 PM, Captain Freako capn.fre...@gmail.comwrote: Hi John, I'm trying to use the GHCI debugger on this code: 20 instance ArrowLoop SF where 21 loop (SF f) = SF $ \as - 22

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

2011-11-01 Thread Ryan Ingram
Never mind, I misread the code, 'zip' and the lazy definition of stream should add the necessary laziness. -- ryan On Tue, Nov 1, 2011 at 3:36 PM, Ryan Ingram ryani.s...@gmail.com wrote: Try swap p = (snd p, fst p) or, equivalently swap ~(x,y) = (y,x) -- ryan On Tue, Nov 1, 2011

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

2011-11-01 Thread John Lask
I can't comment on using ghci debugger to observe evaluation. I have in the past used hood (http://hackage.haskell.org/package/hood) and found it both convenient and useful when trying to observe evaluation order. On 2/11/2011 7:00 AM, Captain Freako wrote: Hi John, I'm trying to use the

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

2011-11-01 Thread Ryan Ingram
First, let's lay out our definitions: unzip [] = ([], []) unzip ((x,y):xys) = (x:xs, y:ys) where (xs,ys) = unzip xys zip [] _ = [] zip _ [] = [] zip (x:xs) (y:ys) = (x,y) : zip xs ys map _ [] = [] map f (x:xs) = f x : map f xs stream ~(a:as) = a : stream as -- equivalently stream xs = head xs

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

2011-10-31 Thread Captain Freako
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

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

2011-10-31 Thread John Lask
On 1/11/2011 1:35 AM, Captain Freako wrote: you need to study ArrowLoop and understand that. In the code rec (y,s')- arr f - (x,s) s- delay s0 - s' the state is 'captured' in the recursive binding. i.e. just like in real circuits the output state s is threaded back as an input. The