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)


为什么是这样?

最佳答案

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")

关于haskell - Haskell变量的类型签名困难,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33364509/

10-13 07:08