Hi!

A couple of months ago, I wrote an exam in an introductory Haskell course and 
failed, all because of an assignment that I was convinced would work, but for 
some reason, it didn't. The assignment was to write a function that would take 
a line, then determine whether it's a palindrome or not. My code follows:

palindrome :: IO ()
palindrome = do putStr "Type in a word"
                s <- getLine
                case s of
                   (s == reverse s)    -> putStrLn (s ++ " is a palindrome")
                   otherwise           -> putStrLn (s ++ " is not a palindrome")

The interesting thing is, that if I change the "case ... of" statement to an 
"if ... then ... else" statement, this magically starts to work. Since I no 
longer am enrolled (I have to take the course next year), I can't ask a 
teacher, but my curiosity still bugs me. Why doesn't this work? And why does it 
work with a "if ... then ...else" statement?
                                          
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to