slide: useful function?

Markus.Schnell@infineon.com Markus.Schnell@infineon.com
Wed, 27 Nov 2002 15:51:33 +0100


I want to propose the following function slide, which is like map, but
depends not on one value of
a list, but on several consecutive ones.

slide :: ([a] -> b) -> [a] -> [b]
slide f [] = []
slide f xs = f xs : slide f (tail xs)

For example, this is useful for a digital filter, like

lowpass = firfilter [0.005178,0.005712,0.00589,0.005712,0.005178]

firfilter :: [Coeff] -> DigitalFilter
firfilter b = slide (firfilter' b)
  where
     firfilter' b = sum . zipWith (*) b


What do you think? Or is there already a function slide, just with another
name?

Markus



--
Markus Schnell, Infineon Technologies AG