fork download
  1. {-# LANGUAGE ExistentialQuantification #-}
  2.  
  3. class Device a
  4.  
  5. data Device' = forall a.(Device a, Show a)=> MakeDevice' a
  6.  
  7. data Hedgehog = Hedgehog
  8. deriving (Show)
  9.  
  10. data GrassSnake = GrassSnake
  11. deriving (Show)
  12.  
  13. instance Device Hedgehog
  14. instance Device GrassSnake
  15.  
  16. device :: String -> Device'
  17. device "Уж" = MakeDevice' Hedgehog
  18. device "Ёж" = MakeDevice' GrassSnake
  19.  
  20. main = putStrLn $ f $ device "Уж"
  21. where f (MakeDevice' a) = show a
Success #stdin #stdout 0.01s 3584KB
stdin
Standard input is empty
stdout
Hedgehog