slide: useful function?
Andreas Abel
abel@informatik.uni-muenchen.de
Thu, 28 Nov 2002 11:31:48 +0100
Markus.Schnell@infineon.com wrote:
> =
> 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)
The function is interesting from the theoretical side since it is an inst=
ance of *redecoration*. Written as
slide :: [a] -> ([a] -> b) -> [b] ,
one sees a similarity with the monadic multiplication (or substitution, h=
ere for the case of lists)
>>=3D :: [a] -> (a -> [b]) -> [b] .
Indeed, slide is the multiplication operation of lists viewed as a *comon=
ad* and hence the dual of ">>=3D".
Read more in
T Uustalu, V Vene. The dual of substitution is redecoration. In K Hammond=
, S Curtis, eds, Trends in Functional Programming 3, pp 99-110. Intellect=
,
Bristol / Portland, OR, 2002. - .ps.gz, 46K (=A9 Intellect) =
http://www.cs.ioc.ee/~tarmo/papers/sfp01-book.ps.gz ,
if you want to be bothered with categorical nonsence ;-)
Cheers,
Andreas
-- =
Andreas Abel --<>-- What if Jesus is right? =
Theoretical Computer Science, University of Munich
http://www.tcs.informatik.uni-muenchen.de/~abel/