我不明白为什么这些函数有错误:
countEqualPairs:: Eq a => [a] -> Int
countEqualPairs (s:ss) = foldr test s ss
test :: Eq a => a -> a -> Int
test s c = if (c == s) then 1 else 0
Run Code Online (Sandbox Code Playgroud)
错误信息:
Run Code Online (Sandbox Code Playgroud)Could not deduce (a ~ Int) from the context (Eq a) bound by the type signature for countEqualPairs :: Eq a => [a] -> Int at Blatt06.hs:30:20-37 `a' is a rigid type variable bound by the type signature for countEqualPairs :: Eq …
haskell ×1