开发者

Showing a Haskell list of tuples with custom syntax

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)]?


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)]

Once you know that show turns a data structure into a pretty string, processing that string to make minor modifications is pretty easy.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜