{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE IncoherentInstances #-} main = do print (g (undefined :: Int)) print (g (undefined :: Bool)) print (g (undefined :: Char)) print (g (undefined :: Float)) print (g (undefined :: Double)) data True class CA t where type A t type A t = True fa :: t -> String instance CA Int where fa _ = "Int" class CB t where type B t type B t = True fb :: t -> String instance CB Bool where fb _ = "Bool" class CC t where type C t type C t = True fc :: t -> String instance CC Char where fc _ = "Char" class CD t where type D t type D t = True fd :: t -> String instance CD Float where fd _ = "Float" class CE t where type E t type E t = True fe :: t -> String instance CE Double where fe _ = "Double" class CAll t t1 t2 t3 t4 t5 where g :: (t1 ~ A t, t2 ~ B t, t3 ~ C t, t4 ~ D t, t5 ~ E t) => t -> String instance (CA t) => CAll t True t2 t3 t4 t5 where g = fa instance (CB t) => CAll t t1 True t3 t4 t5 where g = fb instance (CC t) => CAll t t1 t2 True t4 t5 where g = fc instance (CD t) => CAll t t1 t2 t3 True t5 where g = fd instance (CE t) => CAll t t1 t2 t3 t4 True where g = fe