コードは次のとおりです。
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