Shea Levy
Shea Levy

Reputation: 5415

Require a typeclass instance for a haskell associated type synonym

Is it possible to require that an associated type synonym of some class be an instance of some other class? E.g. with something like the following code (doesn't compile!):

class Test a where
  type Foo a
  instance Show (Foo a)

I would be able to rely on the fact that a Foo a is Showable regardless of the particular a in question.

Obviously I can just add more methods to the class to ensure operations I want on Foo as, but it would be nice to be able to just reuse existing classes.

Upvotes: 2

Views: 135

Answers (1)

Shea Levy
Shea Levy

Reputation: 5415

Found the answer, thanks to lyxia on #haskell:

class (Show (Foo a)) => Test a where
  type Foo a

Upvotes: 1

Related Questions