相关疑难解决方法(0)

如何让GHC为上下文中具有Typeable的GADT生成Data.Typeable实例?

假设我有以下代码:

{-# LANGUAGE GADTs, DeriveDataTypeable, StandaloneDeriving #-}
import Data.Typeable

class Eq t => OnlyEq t
class (Eq t, Typeable t) => BothEqAndTypeable t

data Wrapper a where
    Wrap :: BothEqAndTypeable a => a -> Wrapper a

deriving instance Eq (Wrapper a)
deriving instance Typeable1 Wrapper
Run Code Online (Sandbox Code Playgroud)

然后,以下实例声明工作,没有约束t:

instance OnlyEq (Wrapper t)
Run Code Online (Sandbox Code Playgroud)

并做我期望它做的事情.


但是以下实例声明不起作用:

instance BothEqAndTypeable (Wrapper t)
Run Code Online (Sandbox Code Playgroud)

自GHC - 我使用7.6.1 - 抱怨说:

No instance for (Typeable t)
  arising from the superclasses of an instance declaration
Possible fix: …
Run Code Online (Sandbox Code Playgroud)

haskell ghc derived-instances gadt

7
推荐指数
1
解决办法
901
查看次数

如何在Haskell中为GADT派生数据实例?

我有一个只用过两个不同参数的GADT,ForwardPossible和():

-- | Used when a forward definition is possible.
data ForwardPossible = ForwardPossible deriving (Eq, Ord, Typeable, Data, Show)

-- | GADT which accepts forward definitions if parameter is ForwardPossible.
data OrForward t forward where
  OFKnown :: t -> OrForward t forward
  OFForward :: NamespaceID -> SrcSpan -> BS.ByteString -> OrForward t ForwardPossible

deriving instance Eq t => Eq (OrForward t forward)
deriving instance Ord t => Ord (OrForward t forward)
deriving instance Typeable2 OrForward
deriving instance Show t …
Run Code Online (Sandbox Code Playgroud)

haskell gadt deriving

5
推荐指数
1
解决办法
1211
查看次数

标签 统计

gadt ×2

haskell ×2

derived-instances ×1

deriving ×1

ghc ×1