[Haskell-cafe] Established names for a couple of list functionals?

Stephen Tetley stephen.tetley at gmail.com
Tue Apr 6 16:56:37 EDT 2010


Hello all


Having traversals with special behaviour for the first or last element
is useful for my current work:

-- first element special
--
anacrusisMap :: (a -> b) -> (a -> b) -> [a] -> [b]
anacrusisMap _ _ []     = []
anacrusisMap f g (a:as) = f a : map g as

-- last element special
--
cabooseMap :: (a -> b) -> (a -> b) -> [a] -> [b]
cabooseMap _ _ []     = []
cabooseMap f g (a:as) = step a as where
  step x []           = [g x]
  step x (y:ys)       = f x : step y ys


*Overlay1> anacrusisMap (+1) id [1..10]
[2,2,3,4,5,6,7,8,9,10]

*Overlay1> cabooseMap id (+1) [1..10]
[1,2,3,4,5,6,7,8,9,11]

My question (trivial, but still...) - is there any prior art naming
these functions?

For the record, my name derivation is:

+ anacrusis - musical term, the pickup notes before the first bar in a score.

+ caboose - there was discussion on Haskell-Cafe a couple of months
ago about a list data type with a distinguished terminal type. Caboose
is the name I remember.



Thanks

Stephen


More information about the Haskell-Cafe mailing list