Mitchell<div><br></div><div>You might also be interested in the beginners mailing list. I&#39;ve been enjoying for about a month now! </div><div><br></div><div><a href="http://www.haskell.org/mailman/listinfo/beginners">http://www.haskell.org/mailman/listinfo/beginners</a></div>
<div><br><div class="gmail_quote">On Sat, Apr 24, 2010 at 9:57 PM, Luke Palmer <span dir="ltr">&lt;<a href="mailto:lrpalmer@gmail.com">lrpalmer@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Sat, Apr 24, 2010 at 10:34 PM,  &lt;<a href="mailto:mitchell@kaplan2.com">mitchell@kaplan2.com</a>&gt; wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; I’m just starting to learn, or trying to learn Haskell.  I want to write a<br>
&gt; function to tell me if a number’s prime.  This is what I’ve got:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; f x n y = if n&gt;=y<br>
&gt;<br>
&gt;           then True<br>
&gt;<br>
&gt;           else<br>
&gt;<br>
&gt;           if gcd x n == 1<br>
&gt;<br>
&gt;           then f x (n+1) y<br>
&gt;<br>
&gt;           else False<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; primeQ x = f x 2 y<br>
&gt;<br>
&gt;   where y = floor(sqrt(x))<br>
<br>
</div>Pretty good so far.  The only trouble is that the type of x is<br>
inconsistent. In f it is an integer, but in primeQ it is a floating<br>
point (because you are taking its square root).  Getting past this<br>
just involves understanding Haskell&#39;s type system peculiarities.<br>
Change that last line to:<br>
<br>
    where y = floor (sqrt (fromIntegral x))<br>
<br>
And you should be fine.  (Untested)<br>
<br>
In the future, post the error that you are getting addition to the<br>
code that is causing it.  That helps us find it faster.<br>
<font color="#888888"><br>
Luke<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">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>
</div></div></blockquote></div><br></div>