fork download
  1. class Test t where
  2. test :: t -> String
  3.  
  4. polymorph :: Test t => t -> IO ()
  5. polymorph = putStrLn . test
  6.  
  7. --
  8.  
  9. data Foo = Foo
  10. data Bar = Bar
  11.  
  12. instance Test Foo where
  13. test _ = "foo"
  14.  
  15. instance Test Bar where
  16. test _ = "bar"
  17.  
  18. main = do
  19. polymorph Foo
  20. polymorph Bar
  21.  
Success #stdin #stdout 0s 4584KB
stdin
Standard input is empty
stdout
foo
bar