module Pal where import Data.Char isPalindrome :: String -> Maybe Bool isPalindrome = isOwnReverseMaybe . rejectEmpty . normalize rejectEmpty :: String -> Maybe String rejectEmpty w = case w of [] -> Nothing _ -> Just w normalize :: String -> String normalize = allLowercase . filter notSpace . filter notPunctuation where notSpace = not . isSpace notPunctuation = not . isPunctuation isOwnReverseMaybe :: Maybe String -> Maybe Bool isOwnReverseMaybe = fmap isOwnReverse isOwnReverse :: String -> Bool isOwnReverse word = word == reverse word allLowercase :: String -> String allLowercase = map toLower