这是一段代码:
import System.Environment
myReverse :: [a] -> [a]
myReverse [] = []
main = print (myReverse [])
当我用 GHC 编译它时,我收到以下错误:
[1 of 1] 编译 Main (problem5_myReverse.hs, question5_myReverse.o) problem5_myReverse.hs:6:8: No instance for (Show a0) from a use of
print' The type variable
a0' is ambiguous 可能的修复:添加一个类型签名来修复这些类型变量注意:有几个潜在的实例: instance Show Double -- 定义在GHC.Float' instance Show Float -- Defined in
GHC.Float' instance (Integral a, Show a) => Show (GHC.Real.Ratio a) -- 定义在GHC.Real' ...plus 23 others In the expression: print (myReverse []) In an equation for
main' 中:主 = 打印 (myReverse [ ])
但是当我将签名从更改myReverse::[a]->[a]
为myReverse::[Int]->[Int]
源代码时编译没有任何问题
有人能告诉我如何保留一般签名[a] -> [a]
但使其适用于空整数列表吗?