select and selectSplit
Aaron Denney
wnoise at ofb.net
Fri Feb 15 05:14:33 EST 2008
On 2008-02-15, Cale Gibbard <cgibbard at gmail.com> wrote:
> -- | The 'select' function takes a list and produces a list of pairs
> -- consisting of an element of the list together with a list of the
> -- remaining elements.
> select :: [a] -> [(a,[a])]
> select [] = []
> select (x:xs) = (x,xs) : [(y,x:ys) | (y,ys) <- select xs]
A couple tounge-in-cheek suggestions:
"banishments" -- all possible ways a society can divide itself up into
one banished person, and the rest of society. Or perhaps "hermits".
> -- | The 'selectSplit' function takes a list and produces a list of
> -- triples consisting of a prefix of the list, the element after it,
> -- and the remainder of the list.
> selectSplit :: [a] -> [([a],a,[a])]
> selectSplit [] = []
> selectSplit (x:xs) = ([],x,xs) : [(x:lys,y,rys) | (lys,y,rys) <- selectSplit xs]
I kind of want to call this "positionalPivots", because of the "pivoting
element" used in dividing everything up into elements
less than, and greater than a particular one. This is all possible
choices, but it's using positional order, not comparison order to do
this partioning.
But I actually don't really see much utility in either of these.
Do you have some examples of use, and how they're a commonly abstracted
pattern that deserves using up namespace because of the utility of a
common vocabulary?
--
Aaron Denney
-><-
More information about the Libraries
mailing list