String to list of characters

前端 未结 1 1644
悲哀的现实
悲哀的现实 2021-01-18 09:57

I was wondering if I can convert a string to a list of characters?

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

Essentially, it w

1条回答
  •  太阳男子
    2021-01-18 10:15

    (Collecting comments into an answer)

    Because in haskell, a String is a list of characters, i.e. [Char], just returning the input as given will do.

    example = id
    

    does what you want. Note that id is defined as

    id x = x
    

    Your example "jt5x=!" -> ["j","t","5","x","=","!"] does not match the description: Double quotes "" enclose Strings not single Characters. For characters use single quotes '. You can type

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

    into GHCi and see it returns True. Type map (:[]) "jt5x=!" to actually see ["j","t","5","x","=","!"].

    0 讨论(0)
提交回复
热议问题