问题
The function countPalindromes receives a list of strings and returns a count of how many of the strings are palindromes.
isPalindrome :: String -> Bool
isPalindrome w = w == reverse w
countPalindromes :: [String] -> Int
countPalindromes ss = length filter (== isPalindrome) ss
I know that the function length is applied to two arguments instead of one. I just don't know how to fix this?
回答1:
You may use parentheses to affect function application:
countPalindromes ss = length (filter (== isPalindrome) ss)
The parentheses will cause the entire expression filter (== isPalindrome) ss
to be grouped into a single term, and its result passed on to length
.
This will get you to the next error; I encourage you to read it carefully and see if you can make progress from here yourself, then open a fresh question if you spend, say, fifteen minutes trying to understand it without making progress.
来源:https://stackoverflow.com/questions/49498908/count-number-of-palindromes-in-a-list-of-strings-haskell