本文介绍了以不同的方式显示Haskell列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
[one,two, 3]
显示为
需要它为文件完成感谢
解决方案你可以做插入来自 Data.List
showList :: Show a => [a] - >字符串 showList =插入,。 map showmap show 将每个元素( intercalate,)插入逗号和空格之间的部分并将它们粘合在一起。
使用引号(和任何内部引号正确转义) b $ bhey 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 showThe 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列表?
发布评论