为什么GHC认为类型变量对于具有默认实现的类是不明确的?

时间:2017-01-15 13:24:26

标签: haskell

在以下示例中,我希望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无法解决aA

1 个答案:

答案 0 :(得分:2)

这被证明是一个GHC错误,已在GHC 8.0.2中修复:https://ghc.haskell.org/trac/ghc/ticket/12220