这是一个虚拟示例:
class Test a b where
witness :: a
f :: Test a b => a
f = witness
哈斯克尔然后说
Could not deduce (Test a b0) arising from a use of ‘witness’
from the context (Test a b)
bound by the type signature for f :: Test a b => a
at test.hs:8:6-18
The type variable ‘b0’ is ambiguous
Relevant bindings include f :: a (bound at test.hs:9:1)
In the expression: witness
In an equation for ‘f’: f = witness
错误来自 Haskell 无法推断类型变量的事实,解决方案是从 typeclass 的定义中b0
删除参数。但是,实际上,我做不到。b
Test
我的问题是:是否存在一种明确识别行中给出的b0
显式参数的方法?b
f :: Test a b => a
谢谢。