Having this code to test:
-- | this function checks if string or list are a palindrome
isPalindrome :: (Eq a) => [a] -> Bool
isPalindrome x =
if reverse x == x
then True
else False
I managed to write this:
-- | how do I remove ugly parentheses our of here?
palindromeTest verb = isPalindrome ((\verb -> verb ++ reverse verb) verb ) == True
where types = verb::String
Parentheses look disgusting, how do I work them out?
palindromeTestYour expression:
does not make much sense: an equivalent expression would be:
since
verbin the lambda expression was locally scoped. But you know whatxis: it isverb. So you can replace the expression with:Or in full:
We can also eliminate the
== True, since\x -> x == Trueis equivalent toid:Finally the
where types = verb::Stringis useless as well: Haskell is statically typed, types are resolved at compile time. So this statement does not adds anything. You can restrict the type of verb in the type signature of the function:isPalindromeJust like in
palindromTestit is useless to write== True, there is no reason to write= True, and= Falseif this is based on a condition: simply return the condition itself:You can make it more compact by using
ap: