开发者

display a list differently Haskell?

开发者 https://www.devze.com 2023-03-01 17:37 出处:网络
hey i was wandering if it was possible to show a list: [\"one\", \"two\", \"three\"] to be shown as \"one\", \"two\", \"three\"

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

开发者_如何学C

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消