Haskell ambiguous type -


findmult lst n = [x | x <- lst, x `mod` n == 0]  primes num =      let n = [2..num]         x = ceiling (sqrt num)         nsqrt = [2..x]         not_prime = map (findmult n) nsqrt     in diff2 n (concat not_prime)    

has following problem when try run it

<interactive>:1:0:     ambiguous type variable `t' in constraints:       `realfrac t' arising use of `primes' @ <interactive>:1:0-8       `floating t' arising use of `primes' @ <interactive>:1:0-8       `integral t' arising use of `primes' @ <interactive>:1:0-8     probable fix: add type signature fixes these type variable(s) 

i tried using fromintegral don't think used correctly gives me compilation error. please help.

the purpose of find prime numbers until num.

you error messages when use integral value floating value expected (or vice versa).

in case problem you're calling sqrt, takes floating point value argument, on num making compiler think num floating point value. use num upper limit n, list of integral values (because it's used argument findmult needs list of integral values).

so before calling sqrt on num call fromintegral on it, this:

x = ceiling (sqrt (fromintegral num)) 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -