【发布时间】:2010-12-04 18:55:50
【问题描述】:
我对 Haskell 的类型系统有一个非常普遍的问题。我正在努力熟悉它,我有以下功能:
getN :: Num a => a
getN = 5.0 :: Double
当我尝试编译它时,我收到以下错误:
Couldn't match expected type `a' against inferred type `Double'
`a' is a rigid type variable bound by
the type signature for `getN' at Perlin.hs:15:12
In the expression: 5.0 :: Double
In the definition of `getN': getN = 5.0 :: Double
据我了解,该函数设置为“返回”类 Num 中的一个类型。 Double 属于此类 (http://www.zvon.org/other/haskell/Outputprelude/Num_c.html),所以我原以为在这种情况下“返回”一个 Double 是可以的。
有人可以解释一下吗?
【问题讨论】:
标签: haskell types compiler-errors typeclass type-systems