显示具有自定义语法的哈希克尔元组列表 [英] Showing a Haskell list of tuples with custom syntax
问题描述
我有一个元组列表 [(1,'a','%','yes'),(2,'b','[',no),(3 , 'C', ']', OK)]
。
如何以形式输出此列表[(1,a,%,是),(2,b,[,no),(3,c,], OK)]
?
I have a list of tuples [(1,'a','%',"yes"),(2,'b','[',"no"),(3,'c',']',"ok")]
.
How can I show this list as output in the form of [(1,a,%,yes),(2,b,[,no),(3,c,],ok)]
?
推荐答案
看起来你想要做的转换是去掉引号字符?如果是这样,过滤调用 show
对数据的结果就足够了:
Looks like the transformation you wish to make is to strip out quote characters? If so, filtering the results of calling show
on your data will be enough:
> let x = [(1,'a','%',"yes"),(2,'b','[',"no"),(3,'c',']',"ok")]
然后应用一个过滤器,
Then apply a filter,
> putStrLn . filter (`notElem` "'\"") . show $ x
[(1,a,%,yes),(2,b,[,no),(3,c,],ok)]
一旦您知道 show
变成a数据结构转换为漂亮的字符串,处理该字符串以进行微小的修改非常简单。
Once you know that show
turns a data structure into a pretty string, processing that string to make minor modifications is pretty easy.
这篇关于显示具有自定义语法的哈希克尔元组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!