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

Nicolas Pouillard nicolas.pouillard at gmail.com
Wed Apr 7 03:22:41 EDT 2010


On Tue, 6 Apr 2010 21:56:37 +0100, Stephen Tetley <stephen.tetley at gmail.com> wrote:
> 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

I think it makes for sense to not wire in the map function.

firstOthers :: (a -> b) -> ([a] -> [b]) -> [a] -> [b]
firstOthers _ _ [] = []
firstOthers f g (x:xs) = f x : g xs

Then anacrusisMap is so short that we don't give it a name.

anacrusisMap f = firstOthers f . map

Same thing goes to the other one.

Regards,

-- 
Nicolas Pouillard
http://nicolaspouillard.fr


More information about the Haskell-Cafe mailing list