Haskell错误:无法导出良好的实例/种类不匹配

问题描述 投票:3回答:2

我在Haskell中为日期结构派生Typeable1实例时遇到了麻烦。

这是我的代码:

    {-# LANGUAGE StandaloneDeriving #-}
    {-# LANGUAGE DeriveDataTypeable #-}

    import Data.Typeable (Typeable,Typeable1)

    newtype FooM m a = Foo { unFoo :: (a -> Bar m) -> Bar m }
    newtype Bar m = Atom (m (Maybe (Bar m)))
    type Baz m = Waldo (FooM m ())
    type Waldo a = a

    data Qux m = Qux {
        baz :: Baz m
      , num :: Int
    } -- deriving Typeable1 [1]

    -- deriving instance Typeable1 Qux [2]

取消注释第一个注释[1]会出现此错误:

    Cannot derive well-kinded instance of form `Typeable1 (Qux ...)'
          Class `Typeable1' expects an argument of kind `* -> *'
        In the data type declaration for `Qux'

并且取消注释[2]会出现此错误:

    Kind mis-match
    The first argument of `Typeable1' should have kind `* -> *',
    but `Qux' has kind `(* -> *) -> *'
    In the stand-alone deriving instance for `Typeable1 Qux'

我的问题是:我如何添加Typeable / Typeable1 Qux实例,好吗?

haskell types ghc
2个回答
3
投票

你不能让Qux成为Typeable1的一个实例,但是在现代GHC中,你应该能够得到一个Typeable的实例,它现在具有足够的多态性来处理这种更高级的类型,使Typeable1及其同类不必要。

过时的答案,保留是因为当问题被问到时它是公认的答案:不幸的是,你不能:Typeable层次结构没有类型(* -> *) -> *的类型。由于GHC开始支持种类多态性,因此可能会在未来某个时间修复此问题。


0
投票

看来这个问题目前正在ghc门票#5391中考虑。所以deriving Typeable问题有可能在GHC 7.6中消失。

© www.soinside.com 2019 - 2024. All rights reserved.