简体   繁体   English

Haskell无法将期望的类型“ Double”与实际类型“ Int”匹配

[英]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.

相关问题 Haskell:无法将期望的类型[(Int,Int)]与实际的类型IO [[Int,Int)]相匹配 - Haskell: Couldn't match expected type [(Int, Int)] with actual type IO [(Int,Int)] Haskell 错误 - 无法将类型“[Int] -&gt; String”与“[Char]”匹配; 预期类型:字符串; 实际类型:[Int] -&gt; 字符串 - Haskell Error - Couldn't match type `[Int] -> String' with `[Char]'; Expected type: String; Actual type: [Int] -> String 无法匹配预期类型 [Int] Haskell - Couldn't match expected type [Int] Haskell Haskell编程分配,“无法将期望的类型&#39;Int&#39;与实际类型&#39;[a0]-&gt; Int&#39;匹配”以及其他一些错误 - Haskell Programming Assignment, “Couldn't match expected type ‘Int’ with actual type ‘[a0] -> Int’ ”and a few more Errors Haskell 列表理解类型错误:无法将预期类型“Float”与实际类型“Int”匹配 - Haskell list comprehension type error: Couldn't match expected type ‘Float’ with actual type ‘Int’ Haskell:无法预期实际类型&#39;Int&#39;的&#39;Integer&#39;类型 - Haskell: Couldn't expected type 'Integer' with actual type 'Int' 无法将期望类型“Int”与实际类型“IO [Int]”匹配 - Couldn't match expected type `Int' with actual type `IO [Int]' 无法将预期类型“Int”与实际类型[Int]匹配 - Couldn't match expected type `Int' with actual type [Int] Haskell无法将预期类型的​​float与实际类型&#39;a&#39;匹配 - Haskell couldn't match expected type float with actual type 'a' Haskell:无法将预期类型“ a1”与实际类型“ a”匹配 - Haskell: Couldn't match expected type ‘a1’ with actual type ‘a’
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM