[Haskell-cafe] where to put handy functions?

Chad Scherrer chad.scherrer at gmail.com
Fri Aug 10 11:41:09 EDT 2007


Agreed. I like "select" better too, and the regular vs "Asc" version
is a nice parallel with fromList and fromAscList.

Chad

On 8/10/07, Tillmann Rendel <rendel at rbg.informatik.tu-darmstadt.de> wrote:

> Non-negative is obvious for a list of indexes. Ordered makes sense
> implementation-wise, and should be easy to match for many applications.
> But is it a sensible constraint on a standard library function?
>
> For Data.List, I would prefer a multi-pass select function like this:
>
>    select :: Integral n => [n] -> [a] -> [a]
>    select ns xs = select' 0 ns xs where
>      select' k [] _ = []
>      select' k (n:ns) [] = select' k ns []
>      select' k nns@(n:ns) yys@(y:ys) = case k `compare` n of
>        LT -> select' (succ k) nns ys
>        EQ -> y : select' k ns yys
>        GT -> select nns xs
>
> *Main> select [0, 2, 2, 1] "abcde"
> "accb"
>
> There could be selectAsc for the special case of ordered indexes, to
> avoid keeping the whole input list in memory.
>
>    Tillmann


More information about the Haskell-Cafe mailing list