开发者

Showing a Haskell list of tuples with custom syntax

开发者 https://www.devze.com 2023-02-25 17:49 出处:网络
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)]?L

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

精彩评论

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