以不同的方式显示Haskell列表? [英] display a list differently Haskell?
本文介绍了以不同的方式显示Haskell列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
[one,two, 3]
显示为
one,two,three
需要它为文件完成
感谢
解决方案
你可以做插入
来自 Data.List
showList :: Show a => [a] - >字符串
showList =插入,。 map show
intercalate,
)插入逗号和空格之间的部分并将它们粘合在一起。
hey i was wandering if it was possible to show a list:
["one", "two", "three"]
to be shown as
"one", "two", "three"
need it done for a file
thanks
解决方案
You can do this with intercalate
from Data.List
showList :: Show a => [a] -> String
showList = intercalate ", " . map show
The map show
converts each element to it's string representation with quotes (and any internal quotes properly escaped), while intercalate ", "
inserts commas and spaces between the pieces and glues them together.
这篇关于以不同的方式显示Haskell列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文