Haskell non-digit string list to a different list [closed]
I have a list ['%','&','/']. How can i convert it into the form [%,&开发者_如何学Python,/] ?
myShow :: [Char] -> String
myShow s = concat ["[", intersperse ',' s, "]"]
Use it like this:
putStrLn (myShow ['%','&','/']) -- prints [%,&,/]
But if you want this to work with show and print, you will have to define your own type:
data MyChar = MyChar Char
instance Show MyChar
where show (MyChar ch) = [ch]
And then operate on [MyChar] rather than [Char]:
let myList = map MyChar ['%','&','/']
-- ... do whatever you want with myList ...
print myList -- prints [%,&,/]
"[" ++ intercalate ',' list ++ "]"
intercalate is declared in Data.List.
加载中,请稍侯......
精彩评论