I just write a simple code in Haskell,
coo x y = ((lim-1)*y*(y-1)`div`2) + (y*(y-1)*(sum (map (\j->(x`div`j)-j) [2..lim] )))
where
lim = floor (sqrt x)
but when I use 'coo 10 10' in ghci, it gives me the following error:
<interactive>:3:1:
No instance for (Floating a0) arising from a use of ‘it’
The type variable ‘a0’ is ambiguous
Note: there are several potential instances:
instance Floating Double -- Defined in ‘GHC.Float’
instance Floating Float -- Defined in ‘GHC.Float’
In the first argument of ‘print’, namely ‘it’
In a stmt of an interactive GHCi command: print it
What happened? I am kind of sure I match all types correct.
coo 10 10itself. To see why, type:t cooin GHCi. The types are correct, butcoo 10 10is still polymorphic. You'll have to specify whether you wantcoo 10 10 :: Floatorcoo 10 10 :: Double.FloatorDoubleis notIntegral)sqrt :: Floating a => a -> a; you can usesqrt (fromIntegral x), but be careful of precision loss.