字符串到字符列表

时间:2015-03-30 10:18:03

标签: haskell

我想知道我是否可以将字符串转换为字符列表?

"jt5x=!" -> ["j","t","5","x","=","!"]

基本上,它会是?

example :: String -> [Char]

1 个答案:

答案 0 :(得分:7)

(将评论收集到答案中)

因为在haskell中,String 是一个字符列表,即[Char],只需返回给定的输入即可。

example = id

做你想要的。请注意,id定义为

id x = x

您的示例"jt5x=!" -> ["j","t","5","x","=","!"]与描述不符:双引号""包含StringChar个引号。对于字符,请使用单引号'。您可以输入

"jt5x=!" == ['j','t','5','x','=','!']

进入GHCi并看到它返回True。输入map (:[]) "jt5x=!"即可实际查看["j","t","5","x","=","!"]