{-# language TypeFamilies, UndecidableInstances #-} data A = A data B = B data C = C type family Test a where Test (A -> y) = B -> Test y Test (x -> y) = x -> Test y g :: B -> A g = undefined class Test2 a b where test :: C -> a -> b instance Test2 y y' => Test2 (A -> y) (B -> y') where test c f = test c (\b -> f (g b)) instance {-# OVERLAPPING #-} Test2 y y' => Test2 (x -> y) (x -> y') where test c f = (\x -> test c (f x)) main = undefined