[Haskell-cafe] where to put handy functions?

Brent Yorgey byorgey at gmail.com
Fri Aug 10 07:28:51 EDT 2007


On 8/9/07, Chad Scherrer <chad.scherrer at gmail.com> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070810/c4a4b902/attachment-0001.htm


More information about the Haskell-Cafe mailing list