&gt; For instance your Eq instance could have been written<br><span style="font-family:courier new,monospace">&gt; x == y = (==) `on` (fst . getTuple)</span><br><br>Sorry, wrong arity:<br>(==) = (==) `on` (fst . getTuple)<br>

<br>Okay for the imperative code.<br><br><div class="gmail_quote">2012/2/5 Yves Parès <span dir="ltr">&lt;<a href="mailto:yves.pares@gmail.com">yves.pares@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Concerning your first solution, I don&#39;t understand why you redefine Eq but not Ord instance. Ord will still work by comparing the tuples and not the first elements of said tuples.<br>Plus the good news is you don&#39;t have to do this: just use regular tuples and use sort<b>By </b>or group<b>By </b>functions from Data.List with the &#39;on&#39; function from Data.Function.<br>


For instance your Eq instance could have been written<br><span style="font-family:courier new,monospace">x == y = (==) `on` (fst . getTuple)</span><br><br>With regular tuples you can write &quot;<span style="font-family:courier new,monospace">sortBy (compare `on` fst)</span>&quot;.<br>


<br><br>Plus can you rewrite your original imperative algorithm with the right variable names? You&#39;re using a &#39;d&#39; array that&#39;s not been defined.<br><br><br><div class="gmail_quote">2012/2/5 Haisheng Wu <span dir="ltr">&lt;<a href="mailto:freizl@gmail.com" target="_blank">freizl@gmail.com</a>&gt;</span><br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><font face="&#39;courier new&#39;, monospace"><span style="line-height:21px;color:rgb(17,17,17);font-size:13px">a = [1,1,1,1] </span><br style="line-height:21px;color:rgb(17,17,17);font-size:13px">




<span style="line-height:21px;color:rgb(17,17,17);font-size:13px">b = [0,1,2,3] </span><br style="line-height:21px;color:rgb(17,17,17);font-size:13px"><span style="line-height:21px;color:rgb(17,17,17);font-size:13px">d = [0,0,0,0] </span><br style="line-height:21px;color:rgb(17,17,17);font-size:13px">




<br style="line-height:21px;color:rgb(17,17,17);font-size:13px"><span style="line-height:21px;color:rgb(17,17,17);font-size:13px">for i in b: </span><br style="line-height:21px;color:rgb(17,17,17);font-size:13px">

<span style="line-height:21px;color:rgb(17,17,17);font-size:13px">  for j in c: </span><br style="line-height:21px;color:rgb(17,17,17);font-size:13px"><span style="line-height:21px;color:rgb(17,17,17);font-size:13px">    if (i+j)&lt;3: </span><br style="line-height:21px;color:rgb(17,17,17);font-size:13px">




<span style="line-height:21px;color:rgb(17,17,17);font-size:13px">      d[i+j] += a[i] </span> </font><div><br>
</div><div>My just work implementation in Haskell</div><div><a href="http://hpaste.org/57452" target="_blank">http://hpaste.org/57452</a></div><div><br></div><div>Another people implementation in Haskell with Monad and it turns out complex and very imperatively.</div>




<div><a href="http://hpaste.org/57358" target="_blank">http://hpaste.org/57358</a></div><div><br></div><div>Do you have any cool solution in FP way?</div><div><br></div><div>Thanks.</div><div>-Simon</div>
<br></div></div><div class="im">_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></div></blockquote></div><br>
</blockquote></div><br>