Print empty list in Haskell
This question already has an answer here:
Lists in Haskell are polymorphic in their element's type and as []
contains not enough information you have to supply ghc with it by explicitly giving a type annotation [] :: [Int]
for example.
The error you are getting is due to the fact that the Show
instance for lists is depending on the Show
instance for its elements, and as ghc cannot determine that it assumes that ist has no such instance.
Now you might think everything can be converted to a String
, but then you could think of Int -> Int
and try
show [(+1)]
Which will not work as functions in Haskell have no default Show
instance.
下一篇: 在Haskell中打印空列表