开发者

Displaying list of tuples

displayContacts         :: Contact ->[String]

displayContacts []      =   []

displayContacts (x :xs) =    [show (x)] ++  displayContacts (xs)

after performing above function following result showing with exta "\" why is that and how to overcome this

["(\"Fazaal\",\"Naufer\",7712345678)","(\"Tharanga\",\"Chandasekara\",779876543)"," 
(\"Ruaim\",\"Mohomad开发者_运维技巧\",7798454545)","(\"Yasitha\",\"Lokunarangoda\",7798121212)","
(\"Rochana\",\"Wimalasena\",779878787)","(\"Navin\",\"Dhananshan\",77987345678)","
(    \"Akila\",\"Silva\",7798123123)","(\"Sudantha\",\"Gunawardana\",779812456)"]

i want to display this as "Fazaal" "Naufer" 7712345678 likewise

in my function contact is list of tupples :- [("Isuru","Ranaisnghe",123)]


When you show a string, show "hello", the show instance for String adds in quotes, which are escaped when GHCi prints out a data structure.

There are a few solutions, depending on what your goal is. If you just want cleaner output in GHCi then:

putStrLn $ unlines $ displayContacts contact
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜