<!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 -> if fst x <= 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"><<a moz-do-not-send="true" href="mailto:lbolla@gmail.com">lbolla@gmail.com</a>></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>> splitAt' :: Int -> [a] -> ([a],
[a])<br>
> splitAt' n = foldr (\x <font color="#cc0000">~</font>(z1, z2)
-> if fst x <= n then (snd x : z1, z2)<br>
> else ([], snd x
: z2))<br>
> ([], [])<br>
> . zip [1..]</tt></div>
</blockquote>
</div>
<tt><br>
</tt>
<div><tt>Ozgur</tt></div>
</blockquote>
<tt>Thanks, Ozgur!<br>
</tt>
</body>
</html>