<br><div><span class="gmail_quote">On 8/9/07, <b class="gmail_sendername">Chad Scherrer</b> &lt;<a href="mailto:chad.scherrer@gmail.com">chad.scherrer@gmail.com</a>&gt; 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] -&gt; [a] -&gt; [a]<br>extract = f 0<br>&nbsp;&nbsp;&nbsp;&nbsp;where<br>&nbsp;&nbsp;&nbsp;&nbsp;f _ _ [] = []<br>&nbsp;&nbsp;&nbsp;&nbsp;f _ [] _ = []<br>&nbsp;&nbsp;&nbsp;&nbsp;f k nss@(n:ns) (x:xs) = if n == k then x:f (k+1) ns xs<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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 &quot;extract&quot;?</blockquote><div><br>Other possible names which occur to me include select, slice, mask.&nbsp; I think I like &#39;select&#39; best myself, but &#39;extract&#39; works too.
<br><br>Amusingly, extract is intimately related to function composition. Suppose we have<br><br>listify :: (Int -&gt; Int) -&gt; [Int]<br>listify = flip map [0..]<br><br>Then if f, g :: Int -&gt; 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>