I have a very simple question: Given a function accepting a char and returning a string
test :: Char -> [String]
how can one convert the char into a string? I'm confused over the two types.
The charAt() method returns the character at the specified index in a string. The index of the first character is 0, the second character is 1, and so on.
We can convert a char to a string object in java by using the Character. toString() method.
The toString() and valueOf() methods can both be used to convert a char to a string in Java.
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 = (:[])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With