You can do it using overlapping instances... data A data B b data C c instance Encode A where ... instance Encode b => Encode (B b) where instance Encode c => Encode (C c) where Keean.