[Haskell-cafe] Why doesn't this work? (palindrome :: IO)

Paul R paul.r.ml at gmail.com
Thu Dec 8 11:30:09 CET 2011


Alexej> The interesting thing is, that if I change the "case ... of"
Alexej> statement to an "if ... then ... else" statement, this magically
Alexej> starts to work. Since I no longer am enrolled (I have to take
Alexej> the course next year), I can't ask a teacher, but my curiosity
Alexej> still bugs me. Why doesn't this work? And why does it work with
Alexej> a "if ... then ...else" statement?

maybe you mixed up 'if' and 'case' usages. In fact, 'if' can alway be
translated to 'case' by matching on the boolean condition, like below :

case (s == reverse s) of
  True -> "s is a palindrome"
  False -> "s is not a palindrome



-- 
  Paul



More information about the Haskell-Cafe mailing list