开发者

Haskell non-digit string list to a different list [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜