Re: [Haskell-cafe] Established names for a couple of list functionals?
Hi Henning and Nicolas Thanks, but... I'm not arguing that the functions are generally useful so inter-defined-ness is beside the point. I've a couple of instances, in code that is sadly too complicated and I hope to simplify later, where the describing/naming the traversal currently adds clarity and makes the code marginally more succinct. I recognize this is somewhat unusual - indeed the previous times I've used these two functionals I've refactored them out later - but at the moment they are a benefit, so its the names that I'm asking about not the definitions. Best wishes Stephen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Established names for a couple of list functionals?
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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Established names for a couple of list functionals?
On Tue, 6 Apr 2010 21:56:37 +0100, Stephen Tetley 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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Established names for a couple of list functionals?
Stephen Tetley writes: > -- first element special > -- > anacrusisMap :: (a -> b) -> (a -> b) -> [a] -> [b] > anacrusisMap _ _ [] = [] > anacrusisMap f g (a:as) = f a : map g as I've done something like this, and gave it the extremely imaginative name of firstOthers. But it was an internal non-exported function. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Established names for a couple of list functionals?
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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe