以不同的方式显示Haskell列表?

编程入门 行业动态 更新时间:2024-10-21 07:57:07
本文介绍了以不同的方式显示Haskell列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

[one,two, 3]

显示为

需要它为文件完成

感谢

解决方案

你可以做插入来自 Data.List

showList :: Show a => [a] - >字符串 showList =插入,。 map show

map show 将每个元素( intercalate,)插入逗号和空格之间的部分并将它们粘合在一起。

使用引号(和任何内部引号正确转义) b $ b

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列表?

本文发布于:2023-07-18 04:40:39,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   列表   Haskell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!