开发者

Displaying list of tuples

开发者 https://www.devze.com 2023-03-12 19:45 出处:网络
displayContacts:: Contact ->[String] displayContacts []=[] displayContacts (x :xs) =[show (x)] ++displayContacts (xs)
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

精彩评论

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