我在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
实例,好吗?
你不能让Qux
成为Typeable1
的一个实例,但是在现代GHC中,你应该能够得到一个Typeable
的实例,它现在具有足够的多态性来处理这种更高级的类型,使Typeable1
及其同类不必要。
过时的答案,保留是因为当问题被问到时它是公认的答案:不幸的是,你不能:Typeable
层次结构没有类型(* -> *) -> *
的类型。由于GHC开始支持种类多态性,因此可能会在未来某个时间修复此问题。
看来这个问题目前正在ghc门票#5391中考虑。所以deriving Typeable
问题有可能在GHC 7.6中消失。