I have GHCi, version 7.8.3. I would like to calculate the sum of sqrt elements that are divisible by 10.
If I write [ x | x <- [10..100], x `mod` 10 == 0]or sum [sqrt x | x <- [10..100]]correctly.
[ x | x <- [10..100], x `mod` 10 == 0]
sum [sqrt x | x <- [10..100]]
But if I write sum [ sqrt x | x <- [10..100], x `mod` 10 == 0]when an error is displayed:
sum [ sqrt x | x <- [10..100], x `mod` 10 == 0]
'<interactive>:39:1: No instance for (Show t0) arising from a use of ‘print’ The type variable ‘t0’ is ambiguous Note: there are several potential instances: instance Show Double -- Defined in ‘GHC.Float’ instance Show Float -- Defined in ‘GHC.Float’ instance (Integral a, Show a) => Show (GHC.Real.Ratio a) -- Defined in ‘GHC.Real’ ...plus 23 others In a stmt of an interactive GHCi command: print it'
How to change the command, the correct program?
- , mod Integral a => a, sqrt Floating a => a. , GHC , , , GHCi, - . , GHCi print, show, - , . show, Integral Floating, .
mod
Integral a => a
sqrt
Floating a => a
print
show
Integral
Floating
typecheck, mod sqrt. fromIntegral sqrt:
fromIntegral
sum [sqrt $ fromIntegral x | x <- [10..100], x `mod` 10 == 0]