Допис з розмови
Newbie question...
Path: g2news1.google.com!postnews.google.com!x5g2000yqk.googlegroups.com!not-for-mail
From: maxino <max.korob...@gmail.com>
Newsgroups: comp.lang.haskell
Subject: Re: Newbie question...
Date: Sat, 13 Jun 2009 09:06:53 -0700 (PDT)
Organization: http://groups.google.com
Lines: 50
Message-ID: <0490a562-0350-4567-8f42-c79cbbe1f1b8@x5g2000yqk.googlegroups.com>
References: <d6c02a34-b116-44fa-85e3-50bfcd1a2c44@y7g2000yqa.googlegroups.com>
<871vponwrk.fsf@ixod.org>
NNTP-Posting-Host: 151.66.129.102
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1244909214 13384 127.0.0.1 (13 Jun 2009 16:06:54 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sat, 13 Jun 2009 16:06:54 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: x5g2000yqk.googlegroups.com; posting-host=151.66.129.102;
posting-account=bw0rjgoAAACV5G8KAxHRoqA-uNqvwwFa
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.11)
Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11,gzip(gfe),gzip(gfe)
On Jun 13, 2:28=A0pm, "Mark T.B. Carroll" <Mark.Carr...@Aetion.com>
wrote:
> maxino <max.korob...@gmail.com> writes:
>
> (snip)
>
> > proper_divisors :: Int -> [Int]
> > proper_divisors n =3D [d | d <- [1 .. (floor . sqrt) n], mod n d =3D=3D=
0]
> (snip)
> > =A0 =A0 No instance for (RealFrac Int)
> > =A0 =A0 =A0 arising from a use of `floor' at pd.hs:2:37-41
> (snip)
> > =A0 =A0 No instance for (Floating Int)
> > =A0 =A0 =A0 arising from a use of `sqrt' at pd.hs:2:45-48
>
> the (floor . sqrt) can't accept an n :: Int, because they need n's type
> to be instances of Floating and RealFrac, and Int isn't.
>
> Prelude> :type sqrt
> sqrt :: (Floating a) =3D> a -> a
>
> ... note that the return type is the same as the argument type. From a
> commonsense point of view, one can see part of the reason for the
> complaint about Int as being that for things like sqrt (2::Int) you
> couldn't return an Int answer (at least a correct one!).
>
> Of course,
>
> Prelude> :type mod
> mod :: (Integral a) =3D> a -> a -> a
>
> mod expects an integral n, and you already declared n to be Int.
>
> How about,
>
> proper_divisors n =3D [d | d <- [1 .. (floor . sqrt . fromIntegral) n], m=
od n d =3D=3D 0]
>
> By the way, though I actually much prefer your convention, upper and
> lower camel case seem to have established themselves as the Haskell way,
> so normally one would name your function properDivisors.
>
> Mark
Hey Mark,
Couldn't have asked for a better explanation.
Sorry for the "newbie-ness".
Grazie!
max(ino)