请考虑以下示例:
import Data.Constraint
class Bar a where
bar :: a -> a
foo :: (Bar a) => Dict (Bar a) -> a -> a
foo Dict = bar
Run Code Online (Sandbox Code Playgroud)
在选择Bar
实例时,GHC有两种选择foo
:字典可以使用Bar a
约束中的字典foo
,或者它可以使用运行时Dict
来获取字典.有关字典对应不同实例的示例,请参阅此问题.
GHC使用哪种词典,为什么它是"正确的"选择?