Групи новин: comp.lang.haskell
Від: "Mark T.B. Carroll" <Mark.Carr...@Aetion.com>
Дата: Sat, 13 Jun 2009 08:28:15 -0400
Місцевий час: Сб 13 Чер 2009 15:28
Тема: Re: Newbie question...
(snip)
> proper_divisors :: Int -> [Int] the (floor . sqrt) can't accept an n :: Int, because they need n's type > proper_divisors n = [d | d <- [1 .. (floor . sqrt) n], mod n d == 0] (snip) > No instance for (RealFrac Int) > arising from a use of `floor' at pd.hs:2:37-41 (snip) > No instance for (Floating Int) > arising from a use of `sqrt' at pd.hs:2:45-48 to be instances of Floating and RealFrac, and Int isn't. Prelude> :type sqrt ... note that the return type is the same as the argument type. From a Of course, Prelude> :type mod mod expects an integral n, and you already declared n to be Int. How about, proper_divisors n = [d | d <- [1 .. (floor . sqrt . fromIntegral) n], mod n d == 0] By the way, though I actually much prefer your convention, upper and Mark Ви мусите увійти перед публікацією повідомлень.
Аби надіслати допис, будь ласка, спочатку приєднайтеся до цієї групи.
Будь ласка, поновіть своє прізвисько на сторінці налаштування передплати перед тим, як надіслати свій допис.
У вас немає права надсилання дописів до цієї групи.
| ||||||||||||||