Reputation: 5415
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 Show
able regardless of the particular a
in question.
Obviously I can just add more methods to the class to ensure operations I want on Foo a
s, but it would be nice to be able to just reuse existing classes.
Upvotes: 2
Views: 135
Reputation: 5415
Found the answer, thanks to lyxia on #haskell:
class (Show (Foo a)) => Test a where
type Foo a
Upvotes: 1