haskell 如何在类函数上设置相等约束?

um6iljoc  于 2023-10-19  发布在  其他
关注(0)|答案(1)|浏览(133)

给定

class ProblemC c where
  data ProblemData c :: * -> *
  embedC :: (ProblemData c x ~ x) => x -> c x

data TestThing a f
  = TestA a
  | TestB f
  deriving Functor

instance (ProblemData (TestThing a) x ~ a) => ProblemC (TestThing a) where
  data ProblemData (TestThing a) b = TestData a
  embedC = TestA

我如何得到的东西,类型检查?
本质上,我想要一个类,它将嵌入(和提取,不包括在示例代码中)一些参数化类型。

anhgbhbe

anhgbhbe1#

多亏了西尔维奥的问题,我想通了。我想要的:

class ProblemC c where
  type ProblemData c
  embedC :: ProblemData c -> c (ProblemData c)

data TestThing a f
  = TestA a
  | TestB f
  deriving Functor

instance ProblemC (TestThing a) where
  type ProblemData (TestThing a) = a
  embedC = TestA

相关问题