<div dir="ltr"><div>Why is it the sqrt0 function is so much slower than sqrt1. Does the where clause allow intermediate values to be stored?</div><div>Regards,</div><div>Pat</div><div>sqrt0 :: Int -> Int</div><div>sqrt0 0 =  0 </div><div>sqrt0 1 =  1 </div><div>sqrt0 n =   ((sqrt0 (n - 1)) + (n `quot` sqrt0 (n-1))) `quot` 2 </div><div>-- sqrt0 25 several minutes<br></div><div>sqrt1 :: Int -> Int</div><div>sqrt1 n </div><div> | n ==  0              = 0</div><div> | n ==  1              = 1 </div><div> | otherwise            = div (k + ( div n k)) 2</div><div> where k = sqrt1(n-1)</div><div>-- sqrt1 25 instant<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 9 September 2017 at 05:49, KC <span dir="ltr"><<a href="mailto:kc1956@gmail.com" target="_blank">kc1956@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">One approach <div dir="auto"><br></div><div dir="auto">One function to compute the next iterate</div><div dir="auto"><br></div><div dir="auto">Another function to call the computation function until results are within some tolerance </div><div dir="auto"><br></div><div dir="auto">It's usually presented as separation of control and computation 😎<br><br><div data-smartmail="gmail_signature" dir="auto">--<br>Sent from an expensive device which will be obsolete in a few months<br>Casey</div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sep 3, 2017 1:23 AM, "mike h" <<a href="mailto:mike_k_houghton@yahoo.co.uk" target="_blank">mike_k_houghton@yahoo.co.uk</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi,<div><br></div><div>To help me in learning Haskell I started blogging about some of the things I’ve looked at. </div><div>One such topic was calculating square roots ‘by hand’ and then deriving a Haskell algorithm. </div><div>I wrote about the well known  technique here</div><div><a href="http://gitcommit.co.uk/2017/08/25/the-root-of-the-problem-part-1/" target="_blank">http://gitcommit.co.uk/2017/08<wbr>/25/the-root-of-the-problem-pa<wbr>rt-1/</a></div><div><br></div><div>and it it is really quite a simple method. </div><div><br></div><div>The second part of the post will be an implementation in Haskell. </div><div><br></div><div>I then tried implementing it  and got something that works but really its not very pleasant to look at! And its something I don’t want to post! Some parts are fine but I think I locked myself into the notion that it had to be using State and  really the end result is pretty poor. </div><div><br></div><div>I know this i perhaps a ‘big ask’ but I’d really appreciate any suggestions, solutions, hints etc. I will of course give full attribution. </div><div><br></div><div>I’ve created a gist of the code here</div><div><a href="https://gist.github.com/banditpig" target="_blank">https://gist.github.com/bandit<wbr>pig</a></div><div><br></div><div>Many Thanks</div><div><br></div><div>Mike</div></div><br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bi<wbr>n/mailman/listinfo/beginners</a><br>
<br></blockquote></div></div>
</div></div><br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>

<br>
<p><span lang="EN-GB"><font size="2">This email originated from DIT. If you received this email in error, please delete it from your system. Please note that if you are not the named addressee, disclosing, copying, distributing or taking any action based on the contents of this email or attachments is prohibited. <a href="http://www.dit.ie/" target="_blank">www.dit.ie</a></font></span></p><p><font size="2">Is ó ITBÁC
a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí earráid, scrios
de do chóras é le do thoil. Tabhair ar aird, mura tú an seolaí ainmnithe, go
bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon dáileadh nó ar aon ghníomh
a dhéanfar bunaithe ar an ábhar atá sa ríomhphost nó sna hiatáin seo. <a href="http://www.dit.ie/" target="_blank">www.dit.ie</a></font></p><p><a href="http://www.dit.ie/grangegorman" target="_blank"><font size="2">Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to Grangegorman</font></a></p>