Given that I have the data types
data A a = A a
data B b = B b
and the type class
class C c where
f :: c a -> a
Now the class C expects a type of kind * -> *
, so I can do
instance C A where
f (A a) = a
instance C B where
f (B b) = b
Now given a function such as:
ab :: b -> A (B b)
ab = A . B
How would I declare an instance of C
for the result type?
I first through I might be able to use a type synonym with TypeSynonymInstances
, like this:
type AB b = A (B b)
class C AB where
f (A (B b)) = b
Especially since ghci reports the correct kind:
*Main> :k AB
AB :: * -> *
However, you can't seem to use partially applied type synonyms in instance declarations (or anywhere, for that matter).
Is there some way I can compose the types A
and B
like I can compose the constructors, or some other syntax for declaring an instance for such a nested type?