[英]Why does GHC think that the type variable is ambiguous for a class with a default implementation?
在下面的示例中,我希望 GHC 能够将变量a
限制为类型A
因为这就是我在instance EAmbiguous A
。 但是,当将其加载到 ghci 时,我得到:
由于使用“Main.$dmcount”而产生的不明确的类型变量“a0”
有问题的代码:
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
import GHC.Generics (Rep, Generic)
import GHC.Base (Type)
class EAmbiguous a where
count :: Int
default count :: (Generic a, GenericAmbiguous (Rep a)) => Int
count = genericCount @(Rep a)
class GenericAmbiguous (a :: Type -> Type) where
genericCount :: Int
instance GenericAmbiguous (f p) where
genericCount = 10
data A = A deriving Generic
-- The error happens when defining a body-less instance:
-- • Ambiguous type variable ‘a0’ arising from a use of ‘Main.$dmcount’
-- prevents the constraint ‘(Generic a0)’ from being solved.
instance EAmbiguous A
我一直在研究这个很长一段时间,我相信这应该有效,但我显然错过了一些东西。 所以我的问题是:为什么 GHC 不能解决a
到A
?
结果证明这是 GHC 8.0.2 中修复的 GHC 错误: https : //ghc.haskell.org/trac/ghc/ticket/12220
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.