Mitchell<div><br></div><div>You might also be interested in the beginners mailing list. I'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"><<a href="mailto:lrpalmer@gmail.com">lrpalmer@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 class="im">On Sat, Apr 24, 2010 at 10:34 PM, <<a href="mailto:mitchell@kaplan2.com">mitchell@kaplan2.com</a>> wrote:<br>
> Hi,<br>
><br>
><br>
><br>
> I’m just starting to learn, or trying to learn Haskell. I want to write a<br>
> function to tell me if a number’s prime. This is what I’ve got:<br>
><br>
><br>
><br>
> f x n y = if n>=y<br>
><br>
> then True<br>
><br>
> else<br>
><br>
> if gcd x n == 1<br>
><br>
> then f x (n+1) y<br>
><br>
> else False<br>
><br>
><br>
><br>
><br>
><br>
> primeQ x = f x 2 y<br>
><br>
> 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'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>