问题描述
|
解决方法
\"[\" ++ intercalate \',\' list ++ \"]\"
Data.List
中声明了1ѭ。
,myShow :: [Char] -> String
myShow s = concat [\"[\",intersperse \',\' s,\"]\"]
像这样使用它:
putStrLn (myShow [\'%\',\'&\',\'/\']) -- prints [%,&,/]
但是,如果您希望将它与show
和print
一起使用,则必须定义自己的类型:
data MyChar = MyChar Char
instance Show MyChar
where show (MyChar ch) = [ch]
然后对[MyChar]
而不是[Char]
进行操作:
let myList = map MyChar [\'%\',\'/\']
-- ... do whatever you want with myList ...
print myList -- prints [%,/]