Proposal (Trac ticket #3671): Add takeRec, genericTakeRec and spanRec to Data.List

Jules Bean jules at jellybean.co.uk
Mon Nov 23 06:54:52 EST 2009


Christian Maeder wrote:
> My proposal would be to add a function like
> 
> \begin{code}
> replaceBy :: ([a] -> (b, [a])) -> [a] -> [b]
> replaceBy splt l = case l of
>   [] -> []
>   _ -> let (ft, rt) = splt l in
>     ft : replaceBy splt rt
> \end{code}
> 
> that takes a function "splt" that splits a non-empty list and returns a
> shorter list as second component (to ensure termination).
>

.... if we're in the business of proposing generalised search and 
replace I'd like to propose this one:

http://haskell.org/pipermail/haskell-cafe/2007-July/028032.html

which is along the general lines above but slightly more general.

When I made that posting in 2007 I was hoping for name suggestions. In 
the absence of anythign better I suggest 'Data.List.transform' or the 
more whimsical 'Data.List.transmogrify'.

I would also suggest a convenience function 'Data.List.replace' defined 
from it in the obvious way.

I am also in agreement with 'groupsOf' (which I sometimes called 
'chunksOf' but I like both names) proposed by Yitzchak.

Will all that in mind I oppose this proposal, because whilst I fully 
support filling in some gaps in Data.List I don't think these are the 
best primitives.

Jules


More information about the Libraries mailing list