You need to do D1and D2copies Dinstead of D1 aand D2 a. Then you can quantify extractover aand make a extractreturn afrom Dfor all a.
Since this was probably not very clear (sorry):
class D d where
-- `d` is the type constructor that an instance of `D` (i.e. `D1` or
-- `D2`) and `a` is a new type variable that can be any possible type
extract :: d a -> a
instance D D1 where
extract (Da1 a) = a
extract (Db1 a) = a
source
share