计算字符串列表中的回文数,Haskell [英] Count number of palindromes in a list of strings, Haskell
问题描述
isPalindrome:返回一个字符串列表,并返回一个字符串的个数。 :字符串 - > Bool
isPalindrome w = w ==反向w
countPalindromes :: [String] - > Int
countPalindromes ss = length filter(== isPalindrome)ss
我知道函数长度应用于两个参数而不是一个。我只是不知道如何解决这个问题?
您可以使用括号来影响函数应用程序:
countPalindromes ss = length(filter(== isPalindrome)ss)
括号会导致整个表达式 filter(== isPalindrome)ss
被分组到一个单词中,并且其结果被传递至长度
。
这会让您接触到下一个错误;我鼓励你仔细阅读,看看你是否能从这里自己取得进展,然后开一个新问题,如果你花费了十五分钟的时间试图了解它,而没有取得进展。
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?
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.
这篇关于计算字符串列表中的回文数,Haskell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!