Created
April 10, 2012 21:01
-
-
Save 3noch/2354444 to your computer and use it in GitHub Desktop.
Palindrome Checker in Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Char | |
import IO | |
main = do | |
fileName <- putStr "Enter the name of the file: " >> getLine | |
contents <- readFile fileName | |
mapM_ printOutput (lines contents) | |
where | |
getOutputMessage line = line ++ if isPalindrome line | |
then " is a palindrome!" | |
else " is NOT a palindrome!" | |
printOutput line = putStrLn $ getOutputMessage (prepareLine line) | |
prepareLine = removeWhitespace . map toLower | |
removeWhitespace = filter (not . isWhitespace) | |
where isWhitespace x = x `elem` " \t" | |
isPalindrome xs = xs == reverse xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This needs an
hFlush stdout