Print empty list in Haskell

This question already has an answer here:

  • Print empty list in Haksell 1 answer

  • 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.

    链接地址: http://www.djcxy.com/p/33158.html

    上一篇: 如何处理Haskells gi中的列表框点击

    下一篇: 在Haskell中打印空列表