[Haskell-cafe] I need help getting started
John Bender
john.m.bender at gmail.com
Sun Apr 25 03:01:24 EDT 2010
Mitchell
You might also be interested in the beginners mailing list. I've been
enjoying for about a month now!
http://www.haskell.org/mailman/listinfo/beginners
On Sat, Apr 24, 2010 at 9:57 PM, Luke Palmer <lrpalmer at gmail.com> wrote:
> On Sat, Apr 24, 2010 at 10:34 PM, <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))
>
> Pretty good so far. The only trouble is that the type of x is
> inconsistent. In f it is an integer, but in primeQ it is a floating
> point (because you are taking its square root). Getting past this
> just involves understanding Haskell's type system peculiarities.
> Change that last line to:
>
> where y = floor (sqrt (fromIntegral x))
>
> And you should be fine. (Untested)
>
> In the future, post the error that you are getting addition to the
> code that is causing it. That helps us find it faster.
>
> Luke
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100425/085c8206/attachment.html
More information about the Haskell-Cafe
mailing list