<br><div><span class="gmail_quote">On 8/9/07, <b class="gmail_sendername">Chad Scherrer</b> <<a href="mailto:chad.scherrer@gmail.com">chad.scherrer@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
extract :: [Int] -> [a] -> [a]<br>extract = f 0<br> where<br> f _ _ [] = []<br> f _ [] _ = []<br> f k nss@(n:ns) (x:xs) = if n == k then x:f (k+1) ns xs<br> else f (k+1) nss xs
</blockquote><div><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Finally, even if no one else is using it, it would be good to settle
<br>on reasonable names for things more easily. Is there a better name for<br>this function? Is there a reason not to call it "extract"?</blockquote><div><br>Other possible names which occur to me include select, slice, mask. I think I like 'select' best myself, but 'extract' works too.
<br><br>Amusingly, extract is intimately related to function composition. Suppose we have<br><br>listify :: (Int -> Int) -> [Int]<br>listify = flip map [0..]<br><br>Then if f, g :: Int -> Int, and f is monotonically increasing, we have the identity
<br><br>(listify f) `extract` (listify g) = listify (g . f)<br><br>This randomly occurred to me as I was falling asleep last night and I thought I would share. =)<br><br>-Brent</div></div>