How to use foldr correctly in Haskell?
问题 I'm trying to write a function which behave like this: correctCards :: [Card] -> [Card] -> Int It takes two lists of type Card and check for how many cards are the same. Here is my code: correctCards answer guess = foldr step acc guess where acc = 0 step acc guess | elem (head guess) answer = acc + 1 | otherwise = acc But the types are not match. Can someone tell me where I went wrong? Thanks. 回答1: Have a look at foldr 's type: foldr :: (a -> b -> b) -> b -> [a] -> b Now, that means that the