抱歉打扰您,这是一个简单的问题。我正在尝试学习类型家族扩展的工作原理。当我调试它时,遇到了一个错误,但我无法弄清楚原因。
class Foo a b c where
data T a b c :: *
f :: a -> T a b c
g :: T a b c -> b
h :: c -> a -> b
h c a = g $ f a
错误信息:
Could not deduce (Foo a b c0) arising from a use of ‘g’
from the context (Foo a b c)
bound by the class declaration for ‘Foo’
at DB/Internal/Typecast.hs:(17,1)-(25,19)
The type variable ‘c0’ is ambiguous
Relevant bindings include
a :: a (bound at DB/Internal/Typecast.hs:25:9)
h :: c -> a -> b (bound at DB/Internal/Typecast.hs:25:5)
In the expression: g
In the expression: g $ f a
In an equation for ‘h’: h c a = g $ f a
我不明白为什么在 T a b c
中使用 g
时,c
是模糊的。编译器不能从 f
的 T a b c
中获取 c
的类型吗?
我只想要 g . f
的组合。
f
的T a b c
获取c
的类型吗?” “可以,但是f
又从哪里获取其T a b c
呢?” - Daniel Wagner