这是代码:
class Problem p where
readProblem :: String -> p
solveProblem :: p -> String
readAndSolve = solveProblem . readProblem
这是 GHC 产生的错误消息:
Ambiguous type variable `b0' in the constraint:
(Problem b0) arising from a use of `readProblem'
Probable fix: add a type signature that fixes these type variable(s)
In the second argument of `(.)', namely `readProblem'
In the expression: solveProblem . readProblem
In an equation for `readAndSolve':
readAndSolve = solveProblem . readProblem
据我了解,我必须以某种方式告诉编译器andProblem
使用的实例是同一类型,但我看不出有什么方法可以声明它。为什么它不能自己弄清楚呢?solveProblem
readProblem