
To clarify, by hack I meant that it seemed like a workaround specifically
to keep "case" in the OP's code, when it seemed like they were looking for
the functionality of guards.
amindfv / Tom
On Dec 11, 2011 1:39 PM, "Yitzchak Gale"
Brandon Allbery wrote:
case () of () | s == reverse s -> putStrLn "palindrome" _ -> putStrLn "nope"
Tom Murphy wrote:
This is kind of a hack of case, though. I think what the OP was looking for is isPalindrome word | (word == reverse word) = putStrLn (word ++ " is a palindrome") | otherwise = putStrLn (word ++ " is not a palindrome")
Erm? It's as much of a hack of case as yours is, since the above is actually using case.
I agree with Tom here. While it's true that the compiler internally desugars to case, that low-level compiler transformation doesn't have much to do with the best way to write clear code.
I find that case often creates code that is more confusing and bug-prone. Except when what I really want to express is pattern matching, *and* there is some specific reason here why I don't want to use a named function in a let or where binding. Altogether, it doesn't come up very often for me.
And even for styles that use case more than I do, certainly there is room to call the use of the "case ()" idiom a hack. (Even though I'll admit that I do use it sometimes.)
Regards, Yitz