Haskell难以使用变量的类型签名

时间:2015-10-27 09:46:07

标签: haskell typeclass

tuple :: (Integer a,Fractional b) => (a,b,String)
tuple = (18,5.55,"Charana")

所以这给了我错误

‘Integer’ is applied to too many type arguments
In the type signature for ‘tuple’:
tuple :: (Integer a, Fractional b) => (a, b, String)

为什么会这样?

2 个答案:

答案 0 :(得分:7)

Integer是Haskell中的具体类型,而Integral是一个类型类,用于表示可以表示为整数的事物。因此,您可以选择写:

tuple :: Fractional a => (Integer,a,String)
tuple = (18,5.55,"Charana")

tuple :: (Integral a,Fractional b) => (a,b,String)
tuple = (18,5.55,"Charana")

答案 1 :(得分:4)

Integer只是一种类型。

tuple :: Fractional a => (Integer, a, String)

或许您打算使用Integral a