[英]Haskell Couldn't match expected type ‘Double’ with actual type ‘Int’
This is the code of my program: 这是我程序的代码:
funct :: Double -> Double
funct x = 3/(x^2+1)
zetaRange :: (Int, Int) -> [Double]
zetaRange (x,y) = [ 0.01 * funct n | n <- [x..y] ]
and error, which I'm getting: 和错误,我得到:
Couldn't match expected type 'Double' with actual type 'Int' 无法将预期的类型“ Double”与实际类型“ Int”匹配
In the first argument of 'funct', namely 'n' 在“ funct”的第一个参数中,即“ n”
In the second argument of '(*)', namely 'funct n' 在'(*)'的第二个参数中,即'funct n'
I really newbie to haskell, so trying to fix this error wasn't successful. 我真的是Haskell的新手,因此尝试修复此错误并不成功。 funct is returning Double, so I can't understand why error says that it's actual type is Int. funct返回Double,所以我不明白为什么错误说明它的实际类型是Int。 Please, help! 请帮忙!
您需要将Int
n
转换为Double
:
zetaRange (x,y) = [ 0.01 * funct (fromIntegral n) | n <- [x..y] ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.