<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  <title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
<tt>On 04/16/12 18:21, Lorenzo Bolla wrote:
</tt>
<blockquote cite="mid:20120416142155.GC30186@dell" type="cite">
  <pre wrap=""><tt>Try something like this:
splitAt' n  = foldr (\x zs  -&gt; if fst x &lt;= n then  (snd x : fst zs, snd zs) else              ([], snd x : snd zs)) ([], []) . zip [1..]

I'm no Haskell expert, but I suspect that when pattern-matching z2, it
tries to evaluate it and it hangs...
 
My version does not hang...

hth,
L.

</tt></pre>
</blockquote>
<tt>Thanks, Lorenzo! It works now.<br>
<br>
On 04/16/12 18:55, Ozgur Akgun wrote:</tt>
<blockquote
 cite="mid:CALzazPAs7X+JXD5nu4+E+HiyCeQhbMwJ7qJ+beC0uCzips6gFA@mail.gmail.com"
 type="cite"><tt>You can also use lazy pattern matching.<br>
  <br>
  <a moz-do-not-send="true"
 href="http://en.wikibooks.org/wiki/Haskell/Laziness#Lazy_pattern_matching">http://en.wikibooks.org/wiki/Haskell/Laziness#Lazy_pattern_matching</a><br>
  <br>
  </tt>
  <div class="gmail_quote"><tt>On 16 April 2012 15:21, Lorenzo Bolla <span
 dir="ltr">&lt;<a moz-do-not-send="true" href="mailto:lbolla@gmail.com">lbolla@gmail.com</a>&gt;</span>
wrote:<br>
  </tt>
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
    <div class="im"><tt>&gt; splitAt'    :: Int -&gt; [a] -&gt; ([a],
[a])<br>
&gt; splitAt' n  = foldr (\x <font color="#cc0000">~</font>(z1, z2)
-&gt; if fst x &lt;= n then  (snd x : z1, z2)<br>
&gt;                                       else              ([], snd x
: z2))<br>
&gt;                     ([], [])<br>
&gt;                     . zip [1..]</tt></div>
  </blockquote>
  </div>
  <tt><br>
  </tt>
  <div><tt>Ozgur</tt></div>
</blockquote>
<tt>Thanks, Ozgur!<br>
</tt>
</body>
</html>