This repository has been archived on 2020-07-05. You can view files and clone it, but cannot push or open issues or pull requests.
zurihac2020/test/app/Pal.hs

24 lines
648 B
Haskell

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