为什么此实例无法满足覆盖条件? [英] Why does this instance fail the coverage condition?

查看:52
本文介绍了为什么此实例无法满足覆盖条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在缺少 UndecidableInstances 的情况下,以下实例声明无法满足覆盖条件?似乎,如果在上下文中满足功能依赖关系,则在新实例中满足它.

Why does the following instance declaration fail the coverage condition in the absence of UndecidableInstances? It seems that if the functional dependency is satisfied in the context then it is satisfied in the new instance.

{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE UndecidableInstances #-}

class Foo a b | a -> b where

instance (Foo a b, Foo a' b') => Foo (a, a') (b, b') where

如果我尝试使用类型家族复制相同的东西,就没有问题.

If I try to replicate the same thing with a type family there is no problem.

{-# LANGUAGE TypeFamilies #-}

type family Bar a

type instance Bar (a, b) = (Bar a, Bar b)

推荐答案

我认为选择实例时实际上并未考虑对实例的约束.它们成为要在每个使用地点证明的附加约束,而不是限制实例的适用性.

I believe it's that constraints on instances aren't actually taken into account when selecting an instance. They become additional constraints to be proved at each use site, rather than limiting the applicability of the instance.

因此,您的实例声明有点像 instance Foo(a,b)(c,d),这显然使覆盖条件失败了.

So your instance declaration is kind of equivalent to instance Foo (a, b) (c, d), which rather obviously fails the coverage condition.

添加(Foo ab,Foo a'b')只会使该实例的某些用途导致无此类实例"错误,实际上并不会更改将为其选择实例的类型.

Adding the (Foo a b, Foo a' b') only makes it so that some of the uses of the instance would result in "no such instance" errors, it doesn't actually change the types for which your instance will be selected.

这篇关于为什么此实例无法满足覆盖条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆