I'm trying to write a function that checks if a string is a Palindrome (case insensitive) in Haskell. To make sure capital case characters don't cause an issue, I first convert the string to lower case with toLower (https://hackage.haskell.org/package/text-2.0/docs/Data-Text.html#v:toLower). Then I check if that is equal to the reversed version of the same thing. Here's my code:
{-# LANGUAGE OverloadedStrings #-}
import Data.Text (toLower)
isPalindrome :: String -> Bool
isPalindrome xs = toLower xs == toLower $ reverse xs
I realized toLower uses Text instead of String and we need to use {-# LANGUAGE OverloadedStrings #-} to overload String to Text. But this does not compile.
I replicated this in GHCI as well. I first used :set -XOverloadedStrings to make sure to overload strings. Then I run this:
Prelude Data.Text> toLower $ reverse "sdssSDSS"
<interactive>:92:11: error:
• Couldn't match expected type ‘Data.Text.Internal.Text’
with actual type ‘[Char]’
• In the second argument of ‘($)’, namely ‘reverse "sdssSDSS"’
In the expression: toLower $ reverse "sdssSDSS"
In an equation for ‘it’: it = toLower $ reverse "sdssSDSS"
I don't understand why this doesn't work. If I first run reverse "sdssSDSS" and copy paste the result into toLower it works without an issue.