{-# LANGUAGE FlexibleInstances #-}
class Arg a where
collect' :: [String] -> a
-- extract to IO
instance Arg (IO ()) where
collect' = mapM_ putStrLn
-- extract to [String]
instance Arg [String] where
collect' = id
instance (Show a, Arg r) => Arg (a -> r) where
collect' acc = \x -> collect' (acc ++ [show x])
collect :: Arg t => t
collect = collect' [">> "]
example1 :: [String]
example1 = collect 'a' 2 3.0 () 12
example2 :: IO ()
example2 = collect () "foo" [1,2,3] 42
main = do
putStrLn $ concatMap id example1
example2