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?
palindromeTest
Your expression:
does not make much sense: an equivalent expression would be:
since
verb
in the lambda expression was locally scoped. But you know whatx
is: it isverb
. So you can replace the expression with:Or in full:
We can also eliminate the
== True
, since\x -> x == True
is equivalent toid
:Finally the
where types = verb::String
is 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:isPalindrome
Just like in
palindromTest
it is useless to write== True
, there is no reason to write= True
, and= False
if this is based on a condition: simply return the condition itself:You can make it more compact by using
ap
: