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

Henning Thielemann schlepptop at henning-thielemann.de
Wed Apr 7 11:30:09 EDT 2010


Stephen Tetley schrieb:
> 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.
>   
I build such functions using viewL/viewR or switchL/switchR:
    
http://hackage.haskell.org/packages/archive/utility-ht/0.0.5.1/doc/html/Data-List-HT.html#v%3AviewL



More information about the Haskell-Cafe mailing list