fork download
  1. {-# LANGUAGE TypeFamilies #-}
  2. {-# LANGUAGE MultiParamTypeClasses #-}
  3. {-# LANGUAGE FlexibleInstances #-}
  4. {-# LANGUAGE IncoherentInstances #-}
  5.  
  6. main = do
  7. print (g (undefined :: Int))
  8. print (g (undefined :: Bool))
  9. print (g (undefined :: Char))
  10.  
  11. data True
  12.  
  13. class CA t where
  14. type A t
  15. type A t = True
  16. fa :: t -> String
  17.  
  18. instance CA Int where
  19. fa _ = "Int"
  20.  
  21. class CB t where
  22. type B t
  23. type B t = True
  24. fb :: t -> String
  25.  
  26. instance CB Bool where
  27. fb _ = "Bool"
  28.  
  29. class CC t where
  30. type C t
  31. type C t = True
  32. fc :: t -> String
  33.  
  34. instance CC Char where
  35. fc _ = "Char"
  36.  
  37. class CD t where
  38. type D t
  39. type D t = True
  40. fd :: t -> String
  41.  
  42. instance CD Float where
  43. fd _ = "Float"
  44.  
  45. class CE t where
  46. type E t
  47. type E t = True
  48. fe :: t -> String
  49.  
  50. instance CE Double where
  51. fe _ = "Double"
  52.  
  53. class CAll t t1 t2 t3 t4 t5 where
  54. g :: (t1 ~ A t, t2 ~ B t, t3 ~ C t, t4 ~ D t, t5 ~ E t) => t -> String
  55.  
  56. instance (CA t) => CAll t True t2 t3 t4 t5 where
  57. g = fa
  58.  
  59. instance (CB t) => CAll t t1 True t3 t4 t5 where
  60. g = fb
  61.  
  62. instance (CC t) => CAll t t1 t2 True t4 t5 where
  63. g = fc
  64.  
  65. instance (CD t) => CAll t t1 t2 t3 True t5 where
  66. g = fd
  67.  
  68. instance (CE t) => CAll t t1 t2 t3 t4 True where
  69. g = fe
  70.  
  71.  
Success #stdin #stdout 0s 4696KB
stdin
Standard input is empty
stdout
"Int"
"Bool"
"Char"
"Float"
"Double"