I've recently started to learn Haskell and wanted to convert something to lowercase. I looked up the function "toLower", but it doesn't seem to work.
Prelude> import Data.Text
Prelude Data.Text> toLower "JhELlo"
<interactive>:2:9: error:
* Couldn't match expected type `Text' with actual type `[Char]'
* In the first argument of `toLower', namely `"JhELlo"'
In the expression: toLower "JhELlo"
In an equation for `it': it = toLower "JhELlo"
Prelude Data.Text> toLower 'JhELlo'
<interactive>:3:9: error:
* Syntax error on 'JhELlo'
Perhaps you intended to use TemplateHaskell or TemplateHaskellQuotes
* In the Template Haskell quotation 'JhELlo'
Prelude Data.Text>
It doesn't work, because the version you tried to use operates on Text
, and not String
. Those are two distinct types. You have two options at this point:
1) Use toLower
from Data.Char
; this one operates on a single character, and you can map it over your string:
map toLower "JhELlo"
2) Convert you string to Data.Text
(and optionally back again):
unpack . toLower . pack $ "JhELlo"
There are actually other versions of toLower
around; the one in Data.Sequences
seems to be polymorphic (so should work on both), but it might require pulling in the mono-traversable
package as a dependency.
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