Need to make a program that checks if a given string is a palindrome, it should work whether the case is different, and should ignore non-alphanumeric characters, only using the ord and chr functions in Data.char and regular functions, nothing else. I was able to create the regular palindrome checker:
reverseStr::String->String
reverStr s | s == [] = []
reverseStr (h:t) = reverseStr t ++ [h]
isPalindrome :: String -> Bool
isPalindrome s = s == reverseStr s
I've started work on a function to normalize case:
normalizeCase::String->String
normalizeCase h | h == [] = []
normalizeCase (h) = if ord h > 64 && ord h < 123
then map (chr $ (ord h + 32)) [h]
else h
But I get these errors:
• Couldn't match expected type ‘Char -> Char’
with actual type ‘Char’
• In the first argument of ‘map’, namely ‘(chr $ (ord h + 32))’
In the expression: map (chr $ (ord h + 32)) [h]
In the expression:
if ord h > 64 && ord h < 123 then
map (chr $ (ord h + 32)) [h]
else
h
|
6 | then map (chr $ (ord h + 32)) [h] | ^^^^^^^^^^^^^^^^^^
• Couldn't match type ‘Char’ with ‘[Char]’
Expected type: String
Actual type: Char
• In the expression: h
In the expression:
if ord h > 64 && ord h < 123 then
map (chr $ (ord h + 32)) [h]
else
h
In an equation for ‘normalizeCase’:
normalizeCase [h]
= if ord h > 64 && ord h < 123 then
map (chr $ (ord h + 32)) [h]
else
h
|
7 | else h | ^
I'm still very new to Haskell and have no idea how to implement ord or chr properly so that it works with this checker, so any help would be appreciated!