Actually, I think I can rewrite it this way:<br><br>f xs [] = False<br>f xs (y:ys) | any c ys&#39; = True<br>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | otherwise = f (f (y:xs) ys&#39;) ys<br>&nbsp; where ys&#39; = g y ys<br><br><div class="gmail_quote">
This should help, I think.<br><br>On Sat, Jan 24, 2009 at 12:11 PM, Dan Doel <span dir="ltr">&lt;<a href="mailto:dan.doel@gmail.com">dan.doel@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="Wj3C7c">On Saturday 24 January 2009 11:39:13 am Andrew Wagner wrote:<br>
&gt; This is almost a fold, but seemingly not quite? I know I&#39;ve seem some talk<br>
&gt; of folds that potentially &quot;quit&quot; early. but not sure where I saw that, or<br>
&gt; if it fits.<br>
&gt;<br>
&gt; f xs [] = False<br>
&gt; f xs (y:ys) | any c ys&#39; = True<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | otherwise = f (nub (y:xs)) (ys&#39; ++ ys)<br>
&gt;<br>
&gt; &nbsp; &nbsp;where ys&#39; = g y xs<br>
<br>
</div></div>Quitting early isn&#39;t the problem. For instance, any is defined in terms of<br>
foldr, and it works fine on infinite lists, quitting as soon as it finds a<br>
True. As long as you don&#39;t use the result of the recursive call (which is the<br>
second argument in the function you pass to foldr), it will exit early.<br>
<br>
The problem is that your function doesn&#39;t look structurally recursive, and<br>
that&#39;s what folds (the usual ones, anyway) are: a combinator for structural<br>
recursion. The problem is in your inductive case, where you don&#39;t just recurse<br>
on &quot;ys&quot;, you instead recurse on &quot;ys&#39; ++ ys&quot;, where ys&#39; is the result of an<br>
arbitrary function. folds simply don&#39;t work that way, and only give you access<br>
to the recursive call over the tail, but in a language like Agda, the<br>
termination checker would flag even this definition, and you&#39;d have to, for<br>
instance, write a proof that this actually does terminate, and do induction on<br>
the structure of the proof, or use some other such technique for writing non-<br>
structurally recursive functions.<br>
<font color="#888888"><br>
-- Dan<br>
</font></blockquote></div><br>