Char to string function

前端 未结 4 362
感情败类
感情败类 2021-01-03 18:30

I have a very simple question: Given a function accepting a char and returning a string

test :: Char -> [String]

how can one convert the

4条回答
  •  时光说笑
    2021-01-03 19:25

    In Haskell String is an alias for [Char]:

    type String = [Char]
    

    If you just want a function that converts a single char to a string you could e.g. do

    charToString :: Char -> String
    charToString c = [c]
    

    If you prefer pointfree style you could also write

    charToString :: Char -> String
    charToString = (:[])
    

提交回复
热议问题