Перейти до Домашньої сторінки Груп Google    comp.lang.haskell
Newbie question...

maxino <max.korob...@gmail.com>

Hello,
I've been studying this fascinating language for a few days so I am
pretty new to all this (especially the error messages from the
interpreter!)

I wrote this simple function, which purpose is to generate a list of
proper divisors of a number:

proper_divisors :: Int -> [Int]
proper_divisors n = [d | d <- [1 .. (floor . sqrt) n], mod n d == 0]

Saved in a file, when I :load it from GHCI 6.8.2 this is what I get:

[1 of 1] Compiling Main             ( pd.hs, interpreted )

pd.hs:2:37:
    No instance for (RealFrac Int)
      arising from a use of `floor' at pd.hs:2:37-41
    Possible fix: add an instance declaration for (RealFrac Int)
    In the first argument of `(.)', namely `floor'
    In the expression: (floor . sqrt) n
    In a list comprehension: d <- [1 .. (floor . sqrt) n]

pd.hs:2:45:
    No instance for (Floating Int)
      arising from a use of `sqrt' at pd.hs:2:45-48
    Possible fix: add an instance declaration for (Floating Int)
    In the second argument of `(.)', namely `sqrt'
    In the expression: (floor . sqrt) n
    In a list comprehension: d <- [1 .. (floor . sqrt) n]
Failed, modules loaded: none.

I can imagine that perhaps it has something to do with type conflict
but I can't go any further.
Would someone help?

Thanks,
max(ino)