我想知道我是否可以将字符串转换为字符列表?
"jt5x=!" -> ["j","t","5","x","=","!"]
基本上,它会是?
example :: String -> [Char]
答案 0 :(得分:7)
(将评论收集到答案中)
因为在haskell中,String
是一个字符列表,即[Char]
,只需返回给定的输入即可。
example = id
做你想要的。请注意,id
定义为
id x = x
您的示例"jt5x=!" -> ["j","t","5","x","=","!"]
与描述不符:双引号""
包含String
个Char
个引号。对于字符,请使用单引号'
。您可以输入
"jt5x=!" == ['j','t','5','x','=','!']
进入GHCi并看到它返回True
。输入map (:[]) "jt5x=!"
即可实际查看["j","t","5","x","=","!"]
。