I think it helps to think about what quality means.
class Second a where func2 :: s -> as
A Second instance promises, which func2 defined for any type s . But this does not apply to myFunc2 , because myFunc2 is defined only for those s for which an instance of First exists. This means that since you defined First and Second , it is not possible to use myFunc2 in an instance of Second (unless there is an instance of catch-all forall s . First s , but I suppose not, or you wouldn't bother to make a class).
So, you have to change at least one thing. You can override Second , as suggested by Grzegorz. If you don't like this, you can override Second as
{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleInstances #-} class Second as where func2 :: s -> as instance First s => Second D s where func2 = myFunc2
Note that this says something other than what you originally wrote, because now the Second instance does not guarantee that func2 is polymorphic. But I think it’s closer to what you mean when you say, "make instance D of the second when it evaluates the instance of First." Perhaps this will be acceptable in your code.
source share