slide: useful function?
Jorge Adriano
jadrian@mat.uc.pt
Wed, 27 Nov 2002 16:02:02 +0000
Doesn't seem that usefull to me, you can get the several consecutive ones=
by=20
applying tails to your list.
> 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 [] =3D []
> slide f xs =3D f xs : slide f (tail xs)
slide f =3D map f.init.tails
The init is needed because you don't apply f to the empty List.
If you did, then it would be just.
> slide :: ([a] -> b) -> [a] -> [b]
> slide f [] =3D f [] <---------------
> slide f xs =3D f xs : slide f (tail xs)
slide f =3D map f.tails
J.A.