tuple :: (Integer a,Fractional b) => (a,b,String)
tuple = (18,5.55,"Charana")
Run Code Online (Sandbox Code Playgroud)
所以这给了我错误
‘Integer’ is applied to too many type arguments
In the type signature for ‘tuple’:
tuple :: (Integer a, Fractional b) => (a, b, String)
Run Code Online (Sandbox Code Playgroud)
为什么是这样?
整数是Haskell中的具体类型,而Integral是一个类型类,用于表示可以表示为整数的事物.因此,您可以选择写:
tuple :: Fractional a => (Integer,a,String)
tuple = (18,5.55,"Charana")
Run Code Online (Sandbox Code Playgroud)
要么
tuple :: (Integral a,Fractional b) => (a,b,String)
tuple = (18,5.55,"Charana")
Run Code Online (Sandbox Code Playgroud)