How does one make an equality constraint on a class function?

67 Views Asked by At

Given

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

How do I get something that type checks?

Essentially I want a class that will embed (and extract, not included in example code) some parameterized type.

1

There are 1 best solutions below

0
sfultong On

Thanks to the question from Silvio I figured it out. What I wanted:

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