我正在努力处理Haskell中类型类中的模糊类型变量:
这段代码将我的问题归结为基础知识:
class Problem a b where
foo :: a -> a
bar :: b -> b
baz :: a -> b -> (a, b)
solve :: Problem a b => a -> b -> (a, b)
solve a b = baz (foo a) (bar b)
Run Code Online (Sandbox Code Playgroud)
它没有编译,说当我调用foo和bar时我没有使用的类型变量是不明确的:
Ambiguous type variable `b0' in the constraint:
(Problem a b0) arising from a use of `foo'
Probable fix: add a type signature that fixes these type variable(s)
In the first argument of `baz', …Run Code Online (Sandbox Code Playgroud) haskell ×1