{-# language TypeFamilies, UndecidableInstances #-}

data A = A
data B = B
data C = C

type family Test a where
    Test (A -> y) = Test (B -> y)
    Test (x -> y) = (x -> Test y)

g :: B -> A
g = undefined

class Test2 a where
    test :: C -> a -> Test a
    
instance Test2 (A -> y) where
    test c f = test c (\b -> f (g b))

instance Test2 (x -> y) where
    test c f = (\x -> test c (f x))

main = undefined