GHC无法确定GADT和箭头的类型相等性

时间:2014-05-10 20:32:47

标签: haskell gadt arrows

我无法让GHC注意到箭头表达式中两种类型相同。

data PolyList a where
    Nil :: PolyList '[]
    Cons :: a -> PolyList as -> PolyList (a ': as)

class Recurse a where
    method :: PolyList a -> String

instance Recurse '[] where
    method _ = ""

instance (Show a, Recurse as) => Recurse (a ': as) where
    method = proc input -> case input of
        (Cons a as) -> do
            rest <- method -< as --Could not deduce (Recurse as)
            returnA -< show a ++ rest

    method = proc input -> case input of
        (Cons a as) -> do
            rest <- method -< as :: PolyList as --Works fine
            returnA -< show a ++ rest

    method (Cons a as) =
            let rest = method as --Also works
            in show a ++ rest

完整错误是:

Could not deduce (Recurse as) arising from a use of `method'
from the context (Show a, Recurse as1)
  bound by the instance declaration
Possible fix:
  add (Recurse as) to the context of the instance declaration

为什么不能说as已经有类型PolyList as

编辑:无论如何,这最终会变得毫无用处,因为修复程序似乎会触发ghc #344,但仍未解决。知道问题是什么会很好。

0 个答案:

没有答案