On 8/9/07, Chad Scherrer <[EMAIL PROTECTED]> wrote:
>
> extract :: [Int] -> [a] -> [a]
> extract = f 0
>     where
>     f _ _ [] = []
>     f _ [] _ = []
>     f k nss@(n:ns) (x:xs) = if n == k then x:f (k+1) ns xs
>                             else f (k+1) nss xs


Finally, even if no one else is using it, it would be good to settle
> on reasonable names for things more easily. Is there a better name for
> this function? Is there a reason not to call it "extract"?


Other possible names which occur to me include select, slice, mask.  I think
I like 'select' best myself, but 'extract' works too.

Amusingly, extract is intimately related to function composition. Suppose we
have

listify :: (Int -> Int) -> [Int]
listify = flip map [0..]

Then if f, g :: Int -> Int, and f is monotonically increasing, we have the
identity

(listify f) `extract` (listify g) = listify (g . f)

This randomly occurred to me as I was falling asleep last night and I
thought I would share. =)

-Brent
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to