Hi Lorenzo,<div><br></div><div>what Patrick said was correct. Here&#39;s your program a bit more the Haskell way. Also see: <a href="http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Data-List.html">http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Data-List.html</a></div>
<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><div><br></div><div><br></div><div><div>import Data.List</div><div><br></div></div><div><div>main = do</div><div>  let (past, future) = splitAt 8 [4,55,66,77,88,99,12,9,77,88,99,12,-99]</div>
<div>      subfutures = tail . inits $ future</div><div>  print . takeWhile (`isInfixOf` past) $ subfutures</div></div><div><br></div><div><br></div><div>Regards,</div><div>Thomas</div><div><br></div><div><br></div><div class="gmail_quote">
On Mon, Oct 11, 2010 at 4:09 AM, Patrick LeBoutillier <span dir="ltr">&lt;<a href="mailto:patrick.leboutillier@gmail.com">patrick.leboutillier@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Lorenzo,<br>
<br>
On Sun, Oct 10, 2010 at 4:15 PM, Lorenzo Isella<br>
&lt;<a href="mailto:lorenzo.isella@gmail.com">lorenzo.isella@gmail.com</a>&gt; wrote:<br>
&gt; ...<br>
<div class="im">&gt; In order to find the length of the longest list in the future which has<br>
&gt; already been seen in the past, I could select the &quot;true&quot; values in the<br>
&gt; output of function<br>
&gt;<br>
&gt; iter_find list i<br>
&gt;<br>
&gt; but this is a waste of CPU: I simply would like a while condition to tell my<br>
&gt; function to stop checking new sublists as soon as it finds one which has not<br>
&gt; occurred in the past and I would like a counter (a kind of i++) telling me<br>
&gt; how many times the process has been iterated.<br>
<br>
</div>I&#39;m still a beginner myself, but here&#39;s my take on it. Since Haskell<br>
is lazy, the results<br>
will only be generated as they are needed. For example, if you change:<br>
<div class="im"><br>
  let b = iter_find list i<br>
<br>
</div>for<br>
<br>
  let b = takeWhile id $ iter_find list i<br>
<br>
Haskell will stop generating the list as soon as it sees a False result.<br>
Then you can take the length of b as your answer.<br>
<br>
Patrick<br>
<div class="im"><br>
<br>
&gt; Any suggestion is helpful.<br>
&gt; Cheers<br>
&gt;<br>
&gt; Lorenzo<br>
&gt;<br>
&gt; -------------------------------------------------------------------<br>
&gt;<br>
&gt; import Data.Ord<br>
&gt;<br>
&gt;<br>
&gt; import Data.List<br>
&gt;<br>
&gt; main :: IO ()<br>
&gt;<br>
&gt; main = do<br>
&gt;<br>
&gt;<br>
&gt;  let list = [4,55,66,77,88,99,12,9,77,88,99,12,-99]<br>
&gt;<br>
&gt;  let i = 9<br>
&gt;<br>
&gt;  let b = iter_find list i<br>
&gt;<br>
&gt;  putStrLn &quot;b is, &quot;<br>
&gt;  print b<br>
&gt;<br>
&gt;<br>
&gt; is_sublist sublist list = sublist `isInfixOf` list<br>
&gt;<br>
&gt;<br>
&gt; gen_fut_list list i j = take j $ drop (i-1) list<br>
&gt;<br>
&gt; gen_past_list list i = take (i-1) list<br>
&gt;<br>
&gt; find_in_list list i j = is_sublist (gen_fut_list list i j) (gen_past_list<br>
&gt; list i)<br>
&gt;<br>
&gt; iter_find list i  = map   (find_in_list list i) [1..n]<br>
&gt;                    where n = (length list) - i +1<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Beginners mailing list<br>
&gt; <a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
&gt;<br>
<br>
<br>
<br>
</div><font color="#888888">--<br>
=====================<br>
Patrick LeBoutillier<br>
Rosemère, Québec, Canada<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
</div></div></blockquote></div><br></div>