fork(2) download
  1. {-# LANGUAGE FlexibleInstances, RankNTypes #-} -- (0)
  2.  
  3. class VarArgs a where prc :: String -> a -- (1)
  4.  
  5. instance VarArgs String where prc = id -- (2)
  6.  
  7. instance (Show a, VarArgs r) => VarArgs (a -> r) where -- (3)
  8. prc acc = \x -> prc $ acc ++ "/" ++ show x
  9.  
  10. magic :: VarArgs a => a
  11. magic = (prc "seed:") :: (VarArgs a => a)
  12.  
  13. shmagic _ = (prc "shmagic:")
  14.  
  15. useMagic :: (forall a. VarArgs a => a) -> IO () -- (4)
  16. useMagic f = do
  17. putStrLn $ f 1
  18. putStrLn $ f 1 "qwe"
  19. putStrLn $ f 1 "qwe" [1, 2, 3]
  20.  
  21. main :: IO ()
  22. main = do
  23. putStrLn $ magic 1 2 "qwe" [1,2,3] 123.456
  24. putStrLn $ magic 100500
  25. putStrLn $ magic
  26. useMagic magic -- (5)
  27.  
  28.  
Success #stdin #stdout 0s 8388607KB
stdin
Standard input is empty
stdout
seed:/1/2/"qwe"/[1,2,3]/123.456
seed:/100500
seed:
seed:/1
seed:/1/"qwe"
seed:/1/"qwe"/[1,2,3]