[Haskell-cafe] where to put handy functions?
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
> 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
listify :: (Int -> Int) -> [Int]
listify = flip map [0..]
Then if f, g :: Int -> Int, and f is monotonically increasing, we have the
(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. =)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe