[Haskell-cafe] I need help getting started

David Anderson dave at natulte.net
Sun Apr 25 11:18:22 EDT 2010


On Sun, Apr 25, 2010 at 6:34 AM,  <mitchell at kaplan2.com> wrote:
> Hi,
>
>
>
> I’m just starting to learn, or trying to learn Haskell.  I want to write a
> function to tell me if a number’s prime.  This is what I’ve got:
>
>
>
> f x n y = if n>=y
>
>           then True
>
>           else
>
>           if gcd x n == 1
>
>           then f x (n+1) y
>
>           else False
>
>
>
>
>
> primeQ x = f x 2 y
>
>   where y = floor(sqrt(x))
>
>
>
> The compiler is very unhappy.  Apparently there’s some ambiguity in this,
> and I’m kind of running around in circles.  I’d appreciate any help that
> will get me started.

I won't go over your code, since more skilled people than me are
already helping you out with it. However, once you've finished your
own implementation, you may be interested in
http://blog.natulte.net/posts/2010-04-23-delicious-primes.html . It
may give you some interesting insights, imho as the post's author :-).

- Dave

>
>
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


More information about the Haskell-Cafe mailing list