-- Adding another type class on Entity, but unable to put `GetMessage a` {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableSuperClasses #-} import Data.Kind main :: IO () main = pure () -- "Library" -- making `a` the second variable data Entity (c :: Type -> Constraint) = forall a. (c a) => MkEntity a class (c1 a, c2 a) => (c1 & c2) a instance (c1 a, c2 a) => (c1 & c2) a class HasDataID a where getDependencies :: a -> Entity HasDataID -- ?? instance HasDataID (Entity HasDataID) where getDependencies (MkEntity x) = getDependencies x -- "User" data Foo = Foo Bar data Bar = Bar instance HasDataID Foo where getDependencies (Foo bar) = MkEntity bar instance HasDataID Bar where getDependencies bar = MkEntity bar class GetMessage a where getMessage :: Int -> a -> String instance GetMessage (Entity GetMessage) where getMessage int (MkEntity x) = getMessage int x bla :: Entity (HasDataID & GetMessage) -> Entity (HasDataID & GetMessage) bla e = getDependencies e