Skip to content

Instantly share code, notes, and snippets.

@3noch
Created April 10, 2012 21:01
Show Gist options
  • Save 3noch/2354444 to your computer and use it in GitHub Desktop.
Save 3noch/2354444 to your computer and use it in GitHub Desktop.
Palindrome Checker in Haskell
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
@3noch
Copy link
Author

3noch commented Apr 10, 2012

This needs an hFlush stdout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment