<div dir="ltr"><div>Hi everybody,</div><div>it's my first message on this ML :)</div><div><br></div><div>I don't know if it's appropriate to post this here but I would like to have some feedback with one of my first Haskell code.</div><div>I've been inspired by a recent Numberphile video (<a href="https://www.youtube.com/watch?v=HJ_PP5rqLg0">https://www.youtube.com/watch?v=HJ_PP5rqLg0</a>) how explain the "Russian Peasant" algorithm to do multiplication (here in a nutshell : <a href="https://www.wikihow.com/Multiply-Using-the-Russian-Peasant-Method">https://www.wikihow.com/Multiply-Using-the-Russian-Peasant-Method</a>)</div><div><br></div><div>So I decided I give it a go in Haskell, here is my solution, I appreciate if you give me some feedback on how to improve this code (make it more "idiomatic Haskell")</div><div><br></div><div>NB : I apologize if it's not the right place to ask this kind of review ... in that case, where can I post this ?</div><div><br></div><div>Thanks !<br></div><div><br></div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Droid Sans Mono","monospace",monospace,"Droid Sans Fallback";font-weight:normal;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(86,156,214)">module</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(78,201,176)">DivRusse</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">where</span></div><br><div><span style="color:rgb(220,220,170)">main</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">::</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">IO</span><span style="color:rgb(212,212,212)"> ()</span></div><div><span style="color:rgb(212,212,212)">main = </span><span style="color:rgb(197,134,192)">do</span></div><div><span style="color:rgb(212,212,212)">    putStrLn </span><span style="color:rgb(206,145,120)">"13 x 12 is"</span></div><div><span style="color:rgb(212,212,212)">    print $ russmul </span><span style="color:rgb(181,206,168)">13</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(181,206,168)">12</span></div><br><div><span style="color:rgb(220,220,170)">russmul</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">::</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">Int</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">-></span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">Int</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">-></span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">Int</span></div><div><span style="color:rgb(212,212,212)">russmul a b  =</span></div><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(86,156,214)">let</span><span style="color:rgb(212,212,212)"> filteredPair = filter (\pair -> (fst pair) `mod` </span><span style="color:rgb(181,206,168)">2</span><span style="color:rgb(212,212,212)"> /= </span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(212,212,212)"> ) $ (a,b) : russmulList a b</span></div><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(86,156,214)">in</span><span style="color:rgb(212,212,212)"> foldr (\pair acc -> snd pair + acc) </span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(212,212,212)"> filteredPair</span></div><br><br><div><span style="color:rgb(220,220,170)">russmulList</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">::</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">Int</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">-></span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">Int</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)">-></span><span style="color:rgb(212,212,212)"> [(</span><span style="color:rgb(86,156,214)">Int</span><span style="color:rgb(212,212,212)">, </span><span style="color:rgb(86,156,214)">Int</span><span style="color:rgb(212,212,212)">)]</span></div><div><span style="color:rgb(212,212,212)">russmulList </span><span style="color:rgb(181,206,168)">1</span><span style="color:rgb(212,212,212)"> _ = </span><span style="color:rgb(86,156,214)">[]</span></div><div><span style="color:rgb(212,212,212)">russmulList a b =</span></div><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(86,156,214)">let</span><span style="color:rgb(212,212,212)"> a' = a `div` </span><span style="color:rgb(181,206,168)">2</span></div><div><span style="color:rgb(212,212,212)">        b' = b * </span><span style="color:rgb(181,206,168)">2</span></div><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(86,156,214)">in</span><span style="color:rgb(212,212,212)">  (a', b') : russmulList a' b'</span></div></div></div><div><br></div></div>