假设我有以下列表
[((Int, Int), [[Char]], [[Char]], Bool, Bool, Bool)]
[(Int, Int, [Char], [Char], [Char], [Char], [Char], [Char], [Char], [Char])]
我知道为了能够打印它们,我需要将它们定义为新的数据类型,然后创建一个Show的实例,但是有什么方法可以避免它吗?
提前致谢。
答案 0 :(得分:3)
让[Char]
替换所有String
以摆脱一些括号重载:
[((Int, Int), [String], [String], Bool, Bool, Bool)]
[(Int, Int, String, String, String, String, String, String, String, String)]
这些已经可以打印出来了:
Prelude> let x = replicate 2 ((1,2), ["a", "b"], ["c", "d"], True, False, True) :: [((Int,Int), [String], [String], Bool, Bool, Bool)]
Prelude> :type x -- displays the type of x
x :: [((Int, Int), [String], [String], Bool, Bool, Bool)]
Prelude> print x
[((1,2),["a","b"],["c","d"],True,False,True),((1,2),["a","b"],["c","d"],True,False,True)]
和
Prelude> let x = replicate 2 (1,2,"a","b","c","d","e","f","g","h") :: [(Int,Int,String,String,String,String,String,String,String,String)]
Prelude> :type x
x :: [(Int,
Int,
String,
String,
String,
String,
String,
String,
String,
String)]
Prelude> print x
[(1,2,"a","b","c","d","e","f","g","h"),(1,2,"a","b","c","d","e","f","g","h")]